Skip to content

Commit

Permalink
Added google inurl query as external alternative. resolved #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ndsvw committed Nov 25, 2023
1 parent 44a52ea commit 65a52ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
9 changes: 6 additions & 3 deletions popup/default_popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

</table>

<div id="wayback-area" style="margin-top: 20px; padding-bottom: 5px;">
<b>Alternative:</b> Use
<span id="wayback-link"></span>
<div id="external-alternatives-area" style="margin-top: 20px; padding-bottom: 5px;">
<b>Alternatives:</b>
<ul style="margin-top: 2px;">
<li><span id="wayback-link"></span></li>
<li><span id="google-link"></span></li>
</ul>
</div>
<script type="module" src="default_popup.js"></script>
</body>
Expand Down
34 changes: 23 additions & 11 deletions popup/default_popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ window.onload = async function () {
var DateTime = luxon.DateTime

console.log("onload");
let results = await browser.runtime.sendMessage({ type: "getDateInformation", data: {} });
await updateWaybackMachineArea();

let updateExternalAlternativesAreaPromise = updateExternalAlternativesArea();

let results = await browser.runtime.sendMessage({ type: "getDateInformation", data: {} });

var numerOfResultsHeading = document.getElementById("number-of-results");

if(results === undefined) {
Expand Down Expand Up @@ -47,6 +49,8 @@ window.onload = async function () {

table.appendChild(newRow);
});

await updateExternalAlternativesAreaPromise;
}

function createMethodShortcutLabel(searchMethodShortcut) {
Expand Down Expand Up @@ -100,19 +104,27 @@ function createConfidenceImage(confidence) {
return imageConfidence;
}

async function updateWaybackMachineArea() {
let waybackArea = document.getElementById("wayback-area");
async function updateExternalAlternativesArea() {
let externalAlternativesArea = document.getElementById("external-alternatives-area");
let waybackLink = document.getElementById("wayback-link");
let googleLink = document.getElementById("google-link");
let tabUrl = await browser.runtime.sendMessage({ type: "getUrl", data: {} });
if(tabUrl.startsWith("http")) {
let currentYear = new Date().getFullYear();
let waybackUrl = `https://web.archive.org/web/${currentYear}0000000000*/${tabUrl}`;
const link = document.createElement("a");
link.setAttribute("href", waybackUrl)
link.innerText = "WayBackMachine for this site";
waybackLink.appendChild(link);
waybackArea.style.display = 'block';
const waybackUrl = `https://web.archive.org/web/${currentYear}0000000000*/${tabUrl}`;
const linkWayback = document.createElement("a");
linkWayback.setAttribute("href", waybackUrl)
linkWayback.innerText = "WayBackMachine for this site";
waybackLink.appendChild(linkWayback);

const googleUrl = `https://www.google.com/search?q=inurl%3A${tabUrl}`
const linkGoogle = document.createElement("a");
linkGoogle.setAttribute("href", googleUrl)
linkGoogle.innerText = "'Google-inurl' query for this site";
googleLink.appendChild(linkGoogle);

externalAlternativesArea.style.display = 'block';
} else {
waybackArea.style.display = 'none';
externalAlternativesArea.style.display = 'none';
}
}

0 comments on commit 65a52ce

Please sign in to comment.