Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Search investigations #207

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions content-scripts/components/Navbar/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import jsx from "texsaur";

import { AuthSession } from "../../types";
import HeaderLinks from "./HeaderLinks";
//import HeaderLinks from "./HeaderLinks";
import Authentication from "./HeaderAuthentication";
import SearchBar from "./SearchBar";

//TODO(thePeras): I think we should move this to a separate file dedicated to constants or a folder like `data`
/*
const HEADER_LINKS = {
Estudantes: {
Bolsas: "web_base.gera_pagina?p_pagina=242366",
Expand Down Expand Up @@ -41,7 +43,7 @@ const HEADER_LINKS = {
"Mais opções": "web_base.gera_pagina?p_pagina=1831",
},
};

*/
interface Props {
auth?: AuthSession | null;
}
Expand All @@ -55,7 +57,8 @@ const Header = ({ auth = null }: Props) => {
alt="FEUP Logo"
/>
</a>
<HeaderLinks links={HEADER_LINKS} />
{/*<HeaderLinks links={HEADER_LINKS} /> */}
<SearchBar />
<Authentication auth={auth} />
</header>
);
Expand Down
30 changes: 30 additions & 0 deletions content-scripts/components/Navbar/SearchBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import jsx from "texsaur";

const SearchBar = () => {
return (
<div id="se-search">
<div>
<select id="se-search-select">
<option value="">Tudo</option>
<option value="student">Estudante</option>
<option value="teacher">Professor</option>
</select>
<input
type="text"
id="se-search-bar"
placeholder="Pesquisar no Sigarra"
/>
</div>
<div
className="se-header-link-popover se-popover-open"
style={{ padding: "20px", width: "300px" }}
>
<div class="gcse-searchbox"></div>
<div class="gcse-searchresults"></div>
</div>
</div>
);
};

export default SearchBar;
7 changes: 7 additions & 0 deletions content-scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ const init = async (): Promise<void> => {
}
}

// registerGoogleSearchCallbacks();

// TODO (thePeras): Refactor this
const script = document.createElement("script");
script.src = chrome.runtime.getURL("js/cse.js");
document.body.appendChild(script);

// we run rememberLogin at last, because it's async
// TODO (luisd): make a better mechanism for functions that depend on previous
// steps and might be async
Expand Down
62 changes: 62 additions & 0 deletions content-scripts/prototype.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const myResultsReadyCallback = function (name, q, promos, results, resultsDiv) {
console.log("Executing callback");
const makePromoElt = (promo) => {
const anchor = document.createElement('a');
anchor.href = promo['url'];
anchor.target = '_blank';
anchor.classList.add('gs-title');
const span = document.createElement('span');
span.innerHTML = 'Promo: ' + promo['title'];
anchor.appendChild(span);
return anchor;
};
const makeResultParts = (result) => {
const anchor = document.createElement('a');
anchor.href = result['url'];
anchor.target = '_blank';
anchor.classList.add('gs_title');
anchor.appendChild(document.createTextNode(result['visibleUrl']));
const span = document.createElement('span');
span.innerHTML = ' ' + result['title'];
return [anchor, span];
};

const table = document.createElement('table');
if (promos) {
for (const promo of promos) {
const row = table.insertRow(-1);
const cell = row.insertCell(-1);
cell.appendChild(makePromoElt(promo));
}
resultsDiv.appendChild(table);
resultsDiv.appendChild(document.createElement('br'));
}
if (results) {
const table = document.createElement('table');
for (const result of results) {
const row = table.insertRow(-1);
const cell = row.insertCell(-1);
const [anchor, span] = makeResultParts(result);
cell.appendChild(anchor);
const cell2 = row.insertCell(-1);
cell2.appendChild(span);
}
resultsDiv.appendChild(table);
}
return true;
};

const registerGoogleSearchCallbacks = () => {
window.__gcse = {
//parsetags: "explicit",
searchCallbacks: {
web: {
ready: myResultsReadyCallback,
},
},
};
console.log("Registered callbacks");
console.log(window.__gcse);
};

export default registerGoogleSearchCallbacks;
80 changes: 80 additions & 0 deletions js/cse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let manifest = {
"css/custom.css",
"css/simpler.css",
"js/override-functions.js",
"js/cse.js",
"css/icons.css",
"images/publicationWebsiteLogo/*",
"images/FEUP.svg",
Expand Down
1 change: 1 addition & 0 deletions manifest/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"css/custom.css",
"css/simpler.css",
"js/override-functions.js",
"js/cse.js",
"css/icons.css",
"images/publicationWebsiteLogo/*",
"images/FEUP.svg",
Expand Down
Loading