From 09de46cadff7ff3ca214130ef5d3e9b8b8e14aed Mon Sep 17 00:00:00 2001 From: idk Date: Thu, 24 Sep 2020 20:06:24 -0400 Subject: [PATCH] update for i2p-location --- Makefile | 1 + manifest.json | 6 +++++ scrub.js | 67 ++++++++++++++++++++++----------------------------- 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index 6dc8632..89ed18a 100644 --- a/Makefile +++ b/Makefile @@ -283,6 +283,7 @@ fmt-js: fixjsstyle options/*.js fixjsstyle torrent/*.js fixjsstyle i2pcontrol/*.js + fixjsstyle manifest.json #find . -path ./node_modules -prune -o -name '*.json' -exec fixjsstyle --write {} \; lint: diff --git a/manifest.json b/manifest.json index 5943c43..d1c6290 100644 --- a/manifest.json +++ b/manifest.json @@ -60,6 +60,12 @@ "options_ui": { "page": "options/options.html" }, + "content_scripts": [ + { + "matches": [""], + "js": ["script.js"] + } + ], "background": { "persistent": true, "scripts": [ diff --git a/scrub.js b/scrub.js index 31fec82..9361611 100644 --- a/scrub.js +++ b/scrub.js @@ -600,13 +600,13 @@ var coolheadersSetup = function(e) { }); browser.pageAction.setIcon({path: 'icons/i2plogo.png', tabId: e.tabId}); browser.pageAction.setTitle({ - tabId: e.tabId, - title: header.value - }); + tabId: e.tabId, + title: header.value + }); browser.pageAction.show(e.tabId); break; } - if (header.name.toUpperCase() === 'I2P-TORRENTLOCATION' || header.name.toUpperCase() === 'I2P-TORRENTLOCATION') { + if (header.name.toUpperCase() === 'I2P-TORRENTLOCATION' || header.name.toUpperCase() === 'X-I2P-TORRENTLOCATION') { browser.pageAction.setPopup({ tabId: tabId.id, popup: 'torrent.html' @@ -614,49 +614,40 @@ var coolheadersSetup = function(e) { browser.pageAction.setIcon({path: 'icons/i2plogo.png', tabId: e.tabId}); browser.pageAction.show(e.tabId); browser.pageAction.setTitle({ - tabId: e.tabId, - title: header.value - }); + tabId: e.tabId, + title: header.value + }); break; } } - function checkPageActions(resp) { - function checkBothActions(txt) { - if (txt.includes('meta-i2p-location') || txt.includes('META-I2P-LOCATION')) { - browser.pageAction.setPopup({ - tabId: e.tabId, - popup: 'location.html' - }); - browser.pageAction.setIcon({path: 'icons/i2plogo.png', tabId: e.tabId}); - //TODO: extract meta-i2p-location value from page text - browser.pageAction.setTitle({ - tabId: e.tabId, -// title: header.value - }); - browser.pageAction.show(e.tabId); - } else if (txt.includes('meta-i2p-torrentlocation') || txt.includes('META-I2P-TORRENTLOCATION')) { - browser.pageAction.setPopup({ - tabId: tabId.id, - popup: 'torrent.html' - }); - browser.pageAction.setIcon({path: 'icons/i2plogo.png', tabId: e.tabId}); - browser.pageAction.show(e.tabId); - //TODO: extract meta-i2p-torrentlocation value from page text - browser.pageAction.setTitle({ - tabId: e.tabId, -// title: header.value - }); - } - } - resp.text().then(checkBothActions); - } - fetch(e.url).then(checkPageActions); resolve({responseHeaders: e.responseHeaders}); }, 2000); }); return asyncSetPageAction; } +function getClearTab(tobj) { + function getTabURL(tab) { + browser.tabs.sendMessage( tab.id, {'req':'i2p-location'}).then( response => { + if (response.content.toUpperCase() != "no-alt-location"){ + browser.pageAction.setPopup({ + tabId: tab.id, + popup: 'location.html' + }); + browser.pageAction.setIcon({path: 'icons/i2plogo.png', tabId: tab.id}); + browser.pageAction.setTitle({ + tabId: tab.id, + title: response.content + }); + browser.pageAction.show(tab.id); + } + }); + console.log("(pageaction)", tab.id, tab.url) + } + browser.tabs.get(tobj.tabId).then(getTabURL, onError) +} + +browser.tabs.onActivated.addListener(getClearTab); function reloadTabs(tabs) { for (let tab of tabs) {