Skip to content

Commit

Permalink
Updating options in injected scripts in tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed May 6, 2018
1 parent bfacefb commit 8159600
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ function handleMessage(message, sender)
});
else
browser.contextMenus.remove('copy-clean-link')

browser.tabs.query({}).then(tabs => tabs.forEach(tab =>
browser.tabs.sendMessage(tab.id, 'reloadOptions')
));
})
}

Expand Down
32 changes: 32 additions & 0 deletions cleanlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,38 @@ function cleanLinksInDoc(doc)
}


function undoCleanLinksInDoc(doc)
{
if (typeof doc == 'undefined')
doc = document;

if (typeof doc == 'undefined')
return;


let links = doc.getElementsByTagName('a'),
c = links.length;

for (let l = 0, link = links[l]; l < links.length; link = links[++l])
{
if (link.hasAttribute(attr_cleaned_link))
{
link.setAttribute('href', link.getAttribute(attr_cleaned_link));
link.setAttribute('title', link.getAttribute('title').replace(str_cleanlink_touch.replace(/^\s+/, ''), '').replace(/\s+$/, ''));
link.style.setProperty('border-bottom', '0px', 'important');

// remove highlight styling
if (prefValues.highlight)
highlightLink(link, true);
}
}

//doc.body.setAttribute(attr_cleaned_count, 0);
browser.runtime.sendMessage({ 'cleaned': 0 });
return 0;
}


function textFindLink(node)
{
let pos, selection = node.ownerDocument && node.ownerDocument.defaultView.getSelection();
Expand Down
19 changes: 19 additions & 0 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,22 @@ loadOptions().then(() =>
if (!prefValues.evdm)
cleanLinksInDoc(document);
})

browser.runtime.onMessage.addListener(message =>
{
if (message == 'reloadOptions')
{
var pre_evdm = prefValues.evdm;
return loadOptions().then(() =>
{
if (pre_evdm == prefValues.evdm)
return;
else if (!prefValues.evdm)
cleanLinksInDoc(document);
else
undoCleanLinksInDoc(document);
});
}
else
return Promise.reject('Unexpected message: ' + String(message));
})

0 comments on commit 8159600

Please sign in to comment.