apply: do orphanCheck only on injection
This commit is contained in:
parent
59899b9395
commit
f47b1438dd
13
apply.js
13
apply.js
|
@ -10,12 +10,15 @@ var disabledElements = new Map();
|
||||||
var retiredStyleIds = [];
|
var retiredStyleIds = [];
|
||||||
var iframeObserver;
|
var iframeObserver;
|
||||||
var docRewriteObserver;
|
var docRewriteObserver;
|
||||||
var orphanCheckTimer;
|
|
||||||
|
|
||||||
initIFrameObserver();
|
initIFrameObserver();
|
||||||
requestStyles();
|
requestStyles();
|
||||||
chrome.runtime.onMessage.addListener(applyOnMessage);
|
chrome.runtime.onMessage.addListener(applyOnMessage);
|
||||||
|
|
||||||
|
if (!isOwnPage) {
|
||||||
|
window.dispatchEvent(new CustomEvent(chrome.runtime.id));
|
||||||
|
window.addEventListener(chrome.runtime.id, orphanCheck, true);
|
||||||
|
}
|
||||||
|
|
||||||
function requestStyles(options) {
|
function requestStyles(options) {
|
||||||
// If this is a Stylish page (Edit Style or Manage Styles),
|
// If this is a Stylish page (Edit Style or Manage Styles),
|
||||||
|
@ -367,10 +370,6 @@ function initIFrameObserver() {
|
||||||
const iframesCollection = document.getElementsByTagName('iframe');
|
const iframesCollection = document.getElementsByTagName('iframe');
|
||||||
|
|
||||||
function observer(mutations) {
|
function observer(mutations) {
|
||||||
if (!isOwnPage) {
|
|
||||||
clearTimeout(orphanCheckTimer);
|
|
||||||
orphanCheckTimer = setTimeout(orphanCheck, 1000);
|
|
||||||
}
|
|
||||||
// autoupdated HTMLCollection is superfast
|
// autoupdated HTMLCollection is superfast
|
||||||
if (!iframesCollection[0]) {
|
if (!iframesCollection[0]) {
|
||||||
return;
|
return;
|
||||||
|
@ -436,12 +435,13 @@ function initDocRewriteObserver() {
|
||||||
|
|
||||||
|
|
||||||
function orphanCheck() {
|
function orphanCheck() {
|
||||||
orphanCheckTimer = 0;
|
|
||||||
const port = chrome.runtime.connect();
|
const port = chrome.runtime.connect();
|
||||||
if (port) {
|
if (port) {
|
||||||
port.disconnect();
|
port.disconnect();
|
||||||
|
//console.debug('orphanCheck: still connected');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//console.debug('orphanCheck: disconnected');
|
||||||
|
|
||||||
// we're orphaned due to an extension update
|
// we're orphaned due to an extension update
|
||||||
// we can detach the mutation observer
|
// we can detach the mutation observer
|
||||||
|
@ -454,6 +454,7 @@ function orphanCheck() {
|
||||||
}
|
}
|
||||||
// we can detach event listeners
|
// we can detach event listeners
|
||||||
document.removeEventListener('DOMContentLoaded', onDOMContentLoaded);
|
document.removeEventListener('DOMContentLoaded', onDOMContentLoaded);
|
||||||
|
window.removeEventListener(chrome.runtime.id, orphanCheck, true);
|
||||||
// we can't detach chrome.runtime.onMessage because it's no longer connected internally
|
// we can't detach chrome.runtime.onMessage because it's no longer connected internally
|
||||||
// we can destroy our globals in this context to free up memory
|
// we can destroy our globals in this context to free up memory
|
||||||
[ // functions
|
[ // functions
|
||||||
|
|
Loading…
Reference in New Issue
Block a user