reintroducing background script, which will keep track of frames and videos in currently opened tab (not yet implemented)
This commit is contained in:
parent
85a6a680b9
commit
551bee1724
@ -75,8 +75,66 @@ var _com_sendMessageRuntime = async function(message){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku. Vrne tisti odgovor od tistega okvira, ki prispe prvi.
|
||||||
|
// sends a message to all frames in the currently opened tab. Returns the response of a frame that replied first
|
||||||
|
var _com_sendToAllFrames = async function(message) {
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[Comms::_com_sendToAllFrames] sending message to all frames of currenntly active tab");
|
||||||
|
|
||||||
|
var tabs = await browser.tabs.query({currentWindow: true, active: true});
|
||||||
|
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[Comms::_com_sendToAllFrames] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
|
||||||
|
|
||||||
|
var response = await browser.tabs.sendMessage(tabs[0].id, message);
|
||||||
|
console.log("[Comms::_com_sendToAllFrames] response is this:",response);
|
||||||
|
return response;
|
||||||
|
|
||||||
|
// if(BrowserDetect.firefox){
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// pošlje sporočilce vsem okvirjem v trenutno odprtem zavihku in vrne _vse_ odgovore
|
||||||
|
// sends a message to all frames in currently opened tab and returns all responses
|
||||||
|
var _com_sendToEachFrame = async function(message) {
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[Comms::_com_sendToEveryFrame] sending message to every frames of currenntly active tab");
|
||||||
|
|
||||||
|
try{
|
||||||
|
var tabs = await browser.tabs.query({currentWindow: true, active: true});
|
||||||
|
var frames = await browser.webNavigation.getAllFrames({tabId: tabs[0].id});
|
||||||
|
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[Comms::_com_sendToEveryFrame] we have this many frames:", frames.length, "||| tabs:",tabs,"frames:",frames);
|
||||||
|
|
||||||
|
|
||||||
|
// pošlji sporočilce vsakemu okvirju, potisni obljubo v tabelo
|
||||||
|
// send message to every frame, push promise to array
|
||||||
|
var promises = [];
|
||||||
|
for(var frame in frames){
|
||||||
|
promises.push(browser.tabs.sendMessage(tabs[0].id, message, {frameId: frame.frameId}));
|
||||||
|
}
|
||||||
|
|
||||||
|
// počakajmo, da so obljube izpolnjene
|
||||||
|
// wait for all promises to be kept
|
||||||
|
var responses = Promise.all(promises);
|
||||||
|
|
||||||
|
if(Debug.debug)
|
||||||
|
console.log("[Comms::_com_sendToEveryFrame] we received responses from all frames", responses);
|
||||||
|
|
||||||
|
return responses;
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
console.log("[Comms::_com_sendToEveryFrame] something went wrong when getting frames. this is error:", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var Comms = {
|
var Comms = {
|
||||||
queryTabs: _com_queryTabs,
|
queryTabs: _com_queryTabs,
|
||||||
sendMessage: _com_sendMessage,
|
sendMessage: _com_sendMessage,
|
||||||
sendMessageRuntime: _com_sendMessageRuntime
|
sendMessageRuntime: _com_sendMessageRuntime,
|
||||||
|
sendToEach: _com_sendToEachFrame,
|
||||||
|
sendToAll: _com_sendToAllFrames,
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@ if(Debug.debug)
|
|||||||
console.log("Loading: PageInfo.js");
|
console.log("Loading: PageInfo.js");
|
||||||
|
|
||||||
var _pi_hasVideos = function(){
|
var _pi_hasVideos = function(){
|
||||||
|
// return true;
|
||||||
var videos = document.getElementsByTagName("video");
|
var videos = document.getElementsByTagName("video");
|
||||||
if(videos.length == 0)
|
if(videos.length == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(videos[0].style.display == "none") // in this case ultrawidify doesn't even work
|
// if(videos[0].style.display == "none") // in this case ultrawidify doesn't even work
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
22
js/uw-bg.js
22
js/uw-bg.js
@ -1,29 +1,27 @@
|
|||||||
|
console.log("blabla");
|
||||||
|
|
||||||
async function main(){
|
async function main(){
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw-bg::main] setting up background script");
|
console.log("[uw-bg::main] setting up background script");
|
||||||
|
|
||||||
await Settings.init();
|
await Settings.init();
|
||||||
|
|
||||||
if(BrowserDetect.usebrowser == "chrome")
|
|
||||||
browser.runtime.onMessage.addListener(ChromeCancer.recvmsg);
|
|
||||||
|
|
||||||
else
|
|
||||||
browser.runtime.onMessage.addListener(_uwbg_rcvmsg);
|
|
||||||
|
|
||||||
|
|
||||||
|
browser.tabs.onActivated.addListener(_uwbg_onTabSwitched);
|
||||||
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw-bg::main] listeners registered");
|
console.log("[uw-bg::main] listeners registered");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendMessage(message){
|
async function _uwbg_onTabSwitched(activeInfo){
|
||||||
console.log("SENDING MESSAGE TO CONTENT SCRIPT");
|
|
||||||
var tabs = await Comms.queryTabs({currentWindow: true, active: true});
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw-bg::sendMessage] trying to send message", message, " to tab ", tabs[0], ". (all tabs:", tabs,")");
|
console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB");
|
||||||
|
|
||||||
var response = await browser.tabs.sendMessage(tabs[0].id, message);
|
var tabId = activeInfo.tabId; // just for readability
|
||||||
console.log("[uw-bg::sendMessage] response is this:",response);
|
|
||||||
return response;
|
Comms.sendToEach({"cmd":"has-video"});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _uwbg_rcvmsg(message){
|
async function _uwbg_rcvmsg(message){
|
||||||
|
25
js/uw.js
25
js/uw.js
@ -1,5 +1,17 @@
|
|||||||
if(Debug.debug)
|
if(Debug.debug){
|
||||||
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
console.log("\n\n\n\n\n\n ——— Sᴛλʀᴛɪɴɢ Uʟᴛʀᴀᴡɪᴅɪꜰʏ ———\n << ʟᴏᴀᴅɪɴɢ ᴍᴀɪɴ ꜰɪʟᴇ >>\n\n\n\n");
|
||||||
|
try {
|
||||||
|
if(window.self !== window.top){
|
||||||
|
console.log("%cWe aren't in an iframe.", "color: #afc, background: #174");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.log("%cWe are in an iframe!", "color: #fea, background: #d31", window.self, window.top);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log("%cWe are in an iframe!", "color: #fea, background: #d31");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// global-ish
|
// global-ish
|
||||||
|
|
||||||
@ -80,7 +92,8 @@ var _video_recheck_counter = 0;
|
|||||||
var _video_recheck_period = 60; // on this many retries
|
var _video_recheck_period = 60; // on this many retries
|
||||||
|
|
||||||
function ghettoOnChange(){
|
function ghettoOnChange(){
|
||||||
|
// console.log("..");
|
||||||
|
// console.log("events:", $._data($(document)[0], "events"));
|
||||||
if(_video_recheck_counter++ > _video_recheck_period){
|
if(_video_recheck_counter++ > _video_recheck_period){
|
||||||
_video_recheck_counter = 0;
|
_video_recheck_counter = 0;
|
||||||
|
|
||||||
@ -170,10 +183,10 @@ function receiveMessage(message, sender, sendResponse) {
|
|||||||
console.log("[uw::receiveMessage] we received a message.", message);
|
console.log("[uw::receiveMessage] we received a message.", message);
|
||||||
|
|
||||||
if(message.cmd == "has-videos"){
|
if(message.cmd == "has-videos"){
|
||||||
var anyVideos = PageInfo.hasVideos();
|
var anyVideos = GlobalVars.video != null;
|
||||||
|
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[uw::receiveMessage] returning response:", {response: {"hasVideos": anyVideos }});
|
console.log("[uw::receiveMessage] are there any videos on this page?", anyVideos, GlobalVars.video, this);
|
||||||
|
|
||||||
if(BrowserDetect.usebrowser == "firefox")
|
if(BrowserDetect.usebrowser == "firefox")
|
||||||
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
return Promise.resolve({response: {"hasVideos": anyVideos }});
|
||||||
@ -244,6 +257,6 @@ function receiveMessage(message, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
// $(document).ready(function() {
|
||||||
main();
|
main();
|
||||||
});
|
// });
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
"js/conf/Status.js",
|
"js/conf/Status.js",
|
||||||
"js/conf/ExtensionConf.js",
|
"js/conf/ExtensionConf.js",
|
||||||
|
|
||||||
"js/lib/FullScreenDetect.js",
|
|
||||||
|
|
||||||
"js/modules/PageInfo.js",
|
"js/modules/PageInfo.js",
|
||||||
"js/modules/ArDetect.js",
|
"js/modules/ArDetect.js",
|
||||||
"js/modules/Resizer.js",
|
"js/modules/Resizer.js",
|
||||||
@ -38,8 +36,10 @@
|
|||||||
"all_frames": true
|
"all_frames": true
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs", "storage", "activeTab", "<all_urls>", "*://*.youtube.com/*", "*://youtube.com/*", "*://imdb.com/*", "*://*.imdb.com/*"
|
"tabs", "storage", "webNavigation", "activeTab", "<all_urls>"
|
||||||
],
|
],
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
@ -39,8 +39,34 @@
|
|||||||
"all_frames": true
|
"all_frames": true
|
||||||
}],
|
}],
|
||||||
|
|
||||||
|
"background": {
|
||||||
|
"scripts": [
|
||||||
|
"js/dep/jquery-3.1.1.js",
|
||||||
|
"js/dep/chrome/chrome-extension-async.js",
|
||||||
|
|
||||||
|
"js/lib/BrowserDetect.js",
|
||||||
|
"js/lib/StorageManager.js",
|
||||||
|
"js/lib/Comms.js",
|
||||||
|
|
||||||
|
"js/conf/Debug.js",
|
||||||
|
"js/conf/Settings.js",
|
||||||
|
"js/conf/SitesConf.js",
|
||||||
|
"js/conf/Status.js",
|
||||||
|
"js/conf/ExtensionConf.js",
|
||||||
|
|
||||||
|
|
||||||
|
"js/modules/PageInfo.js",
|
||||||
|
"js/modules/ArDetect.js",
|
||||||
|
"js/modules/Resizer.js",
|
||||||
|
|
||||||
|
"js/conf/Keybinds.js",
|
||||||
|
|
||||||
|
"js/uw-bg.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"tabs", "storage", "activeTab", "<all_urls>", "*://*.youtube.com/*", "*://youtube.com/*", "*://imdb.com/*", "*://*.imdb.com/*"
|
"tabs", "storage", "activeTab", "<all_urls>", "webNavigation"
|
||||||
],
|
],
|
||||||
|
|
||||||
"browser_action": {
|
"browser_action": {
|
||||||
|
@ -66,15 +66,19 @@ async function sendMessage(message){
|
|||||||
|
|
||||||
function check4videos(){
|
function check4videos(){
|
||||||
|
|
||||||
sendMessage({cmd: "has-videos"})
|
Comms.sendToEach({cmd: "has-videos"})
|
||||||
.then(response => {
|
.then(responses => {
|
||||||
if(Debug.debug)
|
if(Debug.debug){
|
||||||
console.log("[popup.js::check4videos] received response:",response);
|
console.log("[popup.js::check4videos] received responses:",responses);
|
||||||
|
for(response of responses){
|
||||||
if(response.response.hasVideos){
|
console.log(response.response);
|
||||||
hasVideos = true;
|
}
|
||||||
openMenu(selectedMenu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if(response.response.hasVideos){
|
||||||
|
// hasVideos = true;
|
||||||
|
// openMenu(selectedMenu);
|
||||||
|
// }
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
@ -89,7 +93,7 @@ function check4conf(){
|
|||||||
sendMessage({cmd: "get-config"})
|
sendMessage({cmd: "get-config"})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(Debug.debug)
|
if(Debug.debug)
|
||||||
console.log("[popup.js::check4conf] received response:",response);
|
console.log("[popup.js::check4conf] received response:",response, response.response);
|
||||||
|
|
||||||
loadConfig(response.response);
|
loadConfig(response.response);
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user