2017-08-05 16:49:25 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-02-23 15:43:26 +00:00
|
|
|
// preventing reregistration if reinjected by tabs.executeScript for whatever reason, just in case
|
|
|
|
if (typeof self.oldCode !== 'string') {
|
|
|
|
self.oldCode = (document.querySelector('body > pre') || document.body).textContent;
|
|
|
|
chrome.runtime.onConnect.addListener(port => {
|
|
|
|
if (port.name !== 'downloadSelf') return;
|
|
|
|
port.onMessage.addListener(({id, timer}) => {
|
|
|
|
fetch(location.href, {mode: 'same-origin'})
|
2018-11-30 01:35:21 +00:00
|
|
|
.then(r => r.text())
|
2020-02-23 15:43:26 +00:00
|
|
|
.then(code => ({id, code: timer && code === self.oldCode ? null : code}))
|
|
|
|
.catch(error => ({id, error: error.message || `${error}`}))
|
|
|
|
.then(msg => {
|
|
|
|
port.postMessage(msg);
|
|
|
|
if (msg.code != null) self.oldCode = msg.code;
|
|
|
|
});
|
2017-09-10 14:05:44 +00:00
|
|
|
});
|
2020-02-23 15:43:26 +00:00
|
|
|
});
|
|
|
|
}
|
2017-08-05 16:49:25 +00:00
|
|
|
|
2020-02-23 15:43:26 +00:00
|
|
|
// passing the result to tabs.executeScript
|
|
|
|
self.oldCode; // eslint-disable-line no-unused-expressions
|