Fixed the 'sometimes extension doesnt load' bug some more: background script sends updates about page updates at most once every two seconds. If the UI is found when the content script is notified of the change, the UI doesn't get reloaded anymore (unless debugmsg
is set to 'true').
This commit is contained in:
parent
9e79048c64
commit
9fc6e058b2
30
js/uw-bg.js
30
js/uw-bg.js
@ -1,11 +1,32 @@
|
||||
debugmsg = false;
|
||||
url_changed = false;
|
||||
|
||||
|
||||
/********************************************
|
||||
**** script-related stuff starts here ****
|
||||
********************************************/
|
||||
|
||||
function gibActiveTab(){
|
||||
return browser.tabs.query({active: true, currentWindow: true});
|
||||
}
|
||||
|
||||
function notifyChange(){
|
||||
return browser.tabs.query({active: true, currentWindow: true}, function(tabs){
|
||||
browser.tabs.sendMessage(tabs[0].id, {message: "page-change"});
|
||||
});
|
||||
|
||||
if(debugmsg)
|
||||
console.log("uw-bg::tab updated. Did we mark for update?", url_changed);
|
||||
|
||||
if(url_changed) //we've already set the proverbial fuse, no need to trigger the function multiple times
|
||||
return;
|
||||
|
||||
url_changed = true; // We mark that the page was changed. We wait for a while before triggering changes.
|
||||
|
||||
setTimeout(function() {
|
||||
console.log("uw-bg::sending a message");
|
||||
browser.tabs.query({active: true, currentWindow: true}, function(tabs){
|
||||
browser.tabs.sendMessage(tabs[0].id, {message: "page-change"});
|
||||
});
|
||||
setTimeout(function(){url_changed = false;}, 1000);
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +34,8 @@ function notifyChange(){
|
||||
browser.tabs.onUpdated.addListener(notifyChange);
|
||||
|
||||
browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
console.log("content script gibed: ", request.test);
|
||||
if(debugmsg)
|
||||
console.log("content script gibed: ", request.test);
|
||||
});
|
||||
|
||||
|
||||
|
15
js/uw.js
15
js/uw.js
@ -1,4 +1,4 @@
|
||||
var debugmsg = true;
|
||||
var debugmsg = false;
|
||||
if(debugmsg){
|
||||
console.log(". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ");
|
||||
console.log("\nLoading ultrawidify (uw)\nIf you can see this, extension at least tried to load\n\nRandom number: ",Math.floor(Math.random() * 20) + 1,"\n");
|
||||
@ -168,6 +168,8 @@ function extSetup(){
|
||||
console.log("==============================================================================================");
|
||||
|
||||
last_location = window.location;
|
||||
|
||||
|
||||
if(debugmsg){
|
||||
console.log("uw::extSetup | our current location is:", last_location);
|
||||
console.log("uw::extSetup | removing existing keydown event from document (useful if extension was previously loaded and we navigated to a different video)");
|
||||
@ -321,6 +323,17 @@ function addCtlButtons(provider_id){
|
||||
// for as long as the array contains elements.
|
||||
//
|
||||
// Yes, that used to be a bug.
|
||||
if(debugmsg){
|
||||
// Če je debugmsg false, potem verjetno ne dodajamo nobenih novih funkcionalnosti, zaradi katerih bi bilo potrebno
|
||||
// ponovno naložiti vmesnik. Zato tega ne storimo, temveč ohranimo stare gumbe. Ker so ok.
|
||||
//
|
||||
// If debugging is false, then we aren't adding any new features that would require us to reload UI. So we leave
|
||||
// the old UI in place, because it should be good enough.
|
||||
|
||||
if(previousElements && previousElements.length > 0){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
while (previousElements && previousElements.length > 0){
|
||||
previousElements[0].parentNode.removeChild(previousElements[0]);
|
||||
|
@ -1,8 +1,7 @@
|
||||
{
|
||||
|
||||
"manifest_version": 2,
|
||||
"name": "Ultrawidify-git",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
|
||||
"icons": {
|
||||
"32":"res/icons/uw-32.png",
|
||||
|
Loading…
Reference in New Issue
Block a user