No need for Stylish->Stylus substitution on new USO
This commit is contained in:
		
							parent
							
								
									e0124f66ba
								
							
						
					
					
						commit
						0ce99afbf5
					
				
							
								
								
									
										46
									
								
								install.js
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								install.js
									
									
									
									
									
								
							| 
						 | 
					@ -3,9 +3,6 @@
 | 
				
			||||||
document.addEventListener('stylishUpdateChrome', onUpdateClicked);
 | 
					document.addEventListener('stylishUpdateChrome', onUpdateClicked);
 | 
				
			||||||
document.addEventListener('stylishInstallChrome', onInstallClicked);
 | 
					document.addEventListener('stylishInstallChrome', onInstallClicked);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
new MutationObserver(waitForBody)
 | 
					 | 
				
			||||||
  .observe(document.documentElement, {childList: true});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
 | 
					chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
 | 
				
			||||||
  // orphaned content script check
 | 
					  // orphaned content script check
 | 
				
			||||||
  if (msg.method == 'ping') {
 | 
					  if (msg.method == 'ping') {
 | 
				
			||||||
| 
						 | 
					@ -13,22 +10,15 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					new MutationObserver((mutations, observer) => {
 | 
				
			||||||
function waitForBody() {
 | 
					  if (document.body) {
 | 
				
			||||||
  if (!document.body) {
 | 
					    observer.disconnect();
 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  this.disconnect();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  rebrand([{addedNodes: [document.body]}]);
 | 
					 | 
				
			||||||
  new MutationObserver(rebrand)
 | 
					 | 
				
			||||||
    .observe(document.body, {childList: true, subtree: true});
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    chrome.runtime.sendMessage({
 | 
					    chrome.runtime.sendMessage({
 | 
				
			||||||
      method: 'getStyles',
 | 
					      method: 'getStyles',
 | 
				
			||||||
      url: getMeta('stylish-id-url') || location.href
 | 
					      url: getMeta('stylish-id-url') || location.href
 | 
				
			||||||
    }, checkUpdatability);
 | 
					    }, checkUpdatability);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					}).observe(document.documentElement, {childList: true});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function checkUpdatability([installedStyle]) {
 | 
					function checkUpdatability([installedStyle]) {
 | 
				
			||||||
| 
						 | 
					@ -133,31 +123,6 @@ function getResource(url) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function rebrand(mutations, observer) {
 | 
					 | 
				
			||||||
  /* stylish to stylus; https://github.com/schomery/stylish-chrome/issues/12 */
 | 
					 | 
				
			||||||
  if (!document.getElementById('hidden-meta') && document.readyState == 'loading') {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  observer.disconnect();
 | 
					 | 
				
			||||||
  const elements = document.getElementsByClassName('install-status');
 | 
					 | 
				
			||||||
  for (let i = elements.length; --i >= 0;) {
 | 
					 | 
				
			||||||
    const walker = document.createTreeWalker(elements[i], NodeFilter.SHOW_TEXT);
 | 
					 | 
				
			||||||
    while (walker.nextNode()) {
 | 
					 | 
				
			||||||
      const node = walker.currentNode;
 | 
					 | 
				
			||||||
      const text = node.nodeValue;
 | 
					 | 
				
			||||||
      const parent = node.parentNode;
 | 
					 | 
				
			||||||
      const extensionHelp = /stylish_chrome/.test(parent.href);
 | 
					 | 
				
			||||||
      if (text.includes('Stylish') && (parent.localName != 'a' || extensionHelp)) {
 | 
					 | 
				
			||||||
        node.nodeValue = text.replace(/Stylish/g, 'Stylus');
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (extensionHelp) {
 | 
					 | 
				
			||||||
        parent.href = 'http://add0n.com/stylus.html';
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function styleSectionsEqual({sections: a}, {sections: b}) {
 | 
					function styleSectionsEqual({sections: a}, {sections: b}) {
 | 
				
			||||||
  if (!a || !b) {
 | 
					  if (!a || !b) {
 | 
				
			||||||
    return undefined;
 | 
					    return undefined;
 | 
				
			||||||
| 
						 | 
					@ -236,13 +201,12 @@ function orphanCheck() {
 | 
				
			||||||
    'checkUpdatability',
 | 
					    'checkUpdatability',
 | 
				
			||||||
    'getMeta',
 | 
					    'getMeta',
 | 
				
			||||||
    'getResource',
 | 
					    'getResource',
 | 
				
			||||||
 | 
					    'onDOMready',
 | 
				
			||||||
    'onInstallClicked',
 | 
					    'onInstallClicked',
 | 
				
			||||||
    'onUpdateClicked',
 | 
					    'onUpdateClicked',
 | 
				
			||||||
    'orphanCheck',
 | 
					    'orphanCheck',
 | 
				
			||||||
    'rebrand',
 | 
					 | 
				
			||||||
    'saveStyleCode',
 | 
					    'saveStyleCode',
 | 
				
			||||||
    'sendEvent',
 | 
					    'sendEvent',
 | 
				
			||||||
    'styleSectionsEqual',
 | 
					    'styleSectionsEqual',
 | 
				
			||||||
    'waitForBody',
 | 
					 | 
				
			||||||
  ].forEach(fn => (window[fn] = null));
 | 
					  ].forEach(fn => (window[fn] = null));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user