123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- var browser = browser || chrome;
- chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
- let value = message.value;
- switch (message.subject) {
- case "tabsUpdated":
- setTimeout(function(blacklist) {
- hideVideo(blacklist);
- }, 2000, value);
- break;
- case "updateBlacklist":
- hideVideo(value);
- default:
- }
- });
- /**
- * Hide video in feed matching keywords
- * @param array blacklist
- */
- function hideVideo(blacklist) {
- console.debug("Hidding video");
- blacklist = blacklist || [];
- let regex = new RegExp(blacklist.join('|'), "i");
- let shelves = document.getElementsByClassName("item-section");
- // Don't match anything
- if (blacklist.length < 1) {
- regex = new RegExp('$^', 'i');
- }
- Array.from(shelves).forEach(function(shelf) {
- let xpathReturn = document.evaluate('.//div[1]/div[2]/ul/li/div/div/div[1]/div[2]/h3/a/text()', shelf, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
- if (xpathReturn.singleNodeValue !== undefined) {
- let title = xpathReturn.singleNodeValue.nodeValue;
- if (regex.exec(title) !== null) {
- // Thhis is necessary to avoid infinite loops with zero-width matches
- shelf.style.display = 'none';
- } else {
- shelf.style.display = 'block';
- }
- }
- });
- }
|