You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

contentScript.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /***********/
  2. /* HELPERS */
  3. /***********/
  4. function checkForShouldKillSticky(result) {
  5. var shouldKillSticky = false;
  6. let matchingPatterns = result.mode == "whitelist" ?
  7. [ ".*" ] :
  8. (typeof result.matchingPatterns != "undefined" ?
  9. result.matchingPatterns.split("\n") :
  10. [ ]);
  11. for (let pattern of matchingPatterns) {
  12. if (pattern &&
  13. !pattern.hasPrefix("#") &&
  14. location.href.match(new RegExp(pattern))) {
  15. shouldKillSticky = true;
  16. break;
  17. }
  18. }
  19. let exclusionPatterns = typeof result.exclusionPatterns != "undefined" ?
  20. result.exclusionPatterns.split("\n") :
  21. [ ];
  22. for (let pattern of exclusionPatterns) {
  23. if (pattern &&
  24. !pattern.hasPrefix("#") &&
  25. location.href.match(new RegExp(pattern))) {
  26. shouldKillSticky = false;
  27. break;
  28. }
  29. }
  30. return shouldKillSticky;
  31. }
  32. function updateIcon(shouldKillSticky) {
  33. chrome.runtime.sendMessage({ "killingStickies" : shouldKillSticky });
  34. }
  35. /******************/
  36. /* INITIALIZATION */
  37. /******************/
  38. function initialize() {
  39. chrome.storage.sync.get([ "matchingPatterns", "exclusionPatterns", "mode" ],
  40. (result) => {
  41. let shouldKillSticky = checkForShouldKillSticky(result);
  42. updateIcon(shouldKillSticky);
  43. window.onload = () => {
  44. if (shouldKillSticky) killSticky();
  45. };
  46. });
  47. }
  48. initialize();