Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function applyScriptToTabHead(tab, source, callback) {
- var isInterrupted = false;
- var code = `
- (() => {
- if(document.head) {
- var i = document.createElement("script");
- i.innerHTML = decodeURI(\"${encodeURI(source)}\");
- document.head.appendChild(i);
- }
- return !!document.head;
- })();
- `;
- var loop = () => {
- chrome.tabs.executeScript(tab.id, {
- code: code,
- runAt: "document_start"
- }, function(args) {
- if (isInterrupted) {
- return;
- }
- if (!args[0]) {
- setTimeout(loop, 1);
- } else {
- callback();
- }
- });
- };
- loop();
- return {
- tab: tab,
- disable: () => {
- isInterrupted = true;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement