COUB.COM - hide selected authors and disliked videos

hides selected authors and disliked videos on COUB.COM

  1. // ==UserScript==
  2. // @name COUB.COM - hide selected authors and disliked videos
  3. // @namespace https://coub.com
  4. // @version 1.2
  5. // @description hides selected authors and disliked videos on COUB.COM
  6. // @author Rhoads
  7. // @license CC-BY-SA-4.0
  8. // @icon https://cs14.pikabu.ru/avatars/2609/m2609364-1795047659.png
  9. // @match https://coub.com/*
  10. // @run-at document-start
  11. // @grant GM_setValue
  12. // @grant GM_getValue
  13. // @grant GM_registerMenuCommand
  14.  
  15. // ==/UserScript==
  16.  
  17. (async function () {
  18. "use strict";
  19.  
  20. // author href with forward '/'
  21. let BLACKLIST = new Set(JSON.parse(GM_getValue("CoubBannedAuthors", "[]")));
  22.  
  23. BLACKLIST.forEach((coubAuthor) =>
  24. {
  25. GM_registerMenuCommand(`Unban ${coubAuthor}`, function() { UnbanAuthor(coubAuthor); });
  26. });
  27.  
  28. let lastCleanedPageID = "-1";
  29.  
  30. function cleanUp(targetNode) {
  31. const lastPage = document.querySelector(".coubs-list__inner .page:last-child");
  32.  
  33. if (lastCleanedPageID === lastPage.dataset.pageId) {
  34. return;
  35. }
  36.  
  37. lastCleanedPageID = lastPage.dataset.pageId;
  38.  
  39. const coubs = lastPage.querySelectorAll("div.coub--normal-card");
  40.  
  41. coubs.forEach((coub) =>
  42. {
  43. //let coubTitle = coub.querySelector("h5.description__title > a")?.title;
  44.  
  45. if (!!coub.querySelector(".coub__dislike-button.-on"))
  46. {
  47. //console.log(`[COUB.COM - BLACKLIST] Removed disliked coub: ${coubTitle}`);
  48. coub.remove();
  49.  
  50. return;
  51. }
  52.  
  53. let coubDescription = coub.querySelector("div.coub-description__about__inner");
  54. let coubAuthor = coubDescription.querySelector("a.hbold.coub-description__about__user")?.getAttribute("href");
  55.  
  56. if (BLACKLIST.has(coubAuthor))
  57. {
  58. //console.log(`[COUB.COM - BLACKLIST] Removed blacklisted coub author: ${coubAuthor}`);
  59. coub.remove();
  60.  
  61. return;
  62. }
  63.  
  64. // add BAN button
  65.  
  66. var button = document.createElement('button');
  67. button.setAttribute('id', 'ButtonBanAuthor');
  68. button.innerHTML = "Ban!";
  69. coubDescription.appendChild(button).addEventListener("click", function() { ButtonBanAuthorClickAction(coubAuthor); }, false);
  70. });
  71. }
  72.  
  73. function ButtonBanAuthorClickAction (coubAuthor) {
  74. //console.log(`[COUB.COM - BLACKLIST] Blacklist coub author: ${coubAuthor}`);
  75. BLACKLIST.add(coubAuthor);
  76. SaveBlacklist();
  77. }
  78.  
  79. function UnbanAuthor(coubAuthor) {
  80. //console.log(`[COUB.COM - BLACKLIST] Unban: ${coubAuthor}`);
  81. BLACKLIST.delete(coubAuthor);
  82. SaveBlacklist();
  83. }
  84.  
  85. function SaveBlacklist() {
  86. GM_setValue("CoubBannedAuthors", JSON.stringify([...BLACKLIST]));
  87. }
  88.  
  89. async function waitUntilExists(selector) {
  90. return new Promise(function check(resolve, reject) {
  91. let el = document.querySelector(selector);
  92.  
  93. if (el) {
  94. return resolve(el);
  95. }
  96.  
  97. setTimeout(function () {
  98. check(resolve, reject);
  99. }, 100);
  100. });
  101. }
  102.  
  103. await waitUntilExists(".coubs-list__inner > .page");
  104.  
  105. cleanUp();
  106.  
  107. window.addEventListener("scroll", cleanUp);
  108. })();