Reddit FL - Hello Tinder

Ajoute un bouton qui cache les top-comments qui ne parlent PAS de Tinder sur le FL de /r/france (Old Reddit).

  1. // ==UserScript==
  2. // @name Reddit FL - Hello Tinder
  3. // @author RandomUsername404
  4. // @namespace https://greatest.deepsurf.us/en/users/105361-randomusername404
  5. // @version 0.8
  6. // @description Ajoute un bouton qui cache les top-comments qui ne parlent PAS de Tinder sur le FL de /r/france (Old Reddit).
  7. // @run-at document-start
  8. // @include https://old.reddit.com/r/france/*
  9. // @grant none
  10. // @icon https://i.imgtc.com/kAtByTB.png
  11. // ==/UserScript==
  12.  
  13. var indexLastLinkMoreCmts;
  14. var targetNode;
  15. var config;
  16. var callback;
  17. var observer;
  18. var bool;
  19. var regex = new RegExp('(?:^|\\W)tinder|tinderette|okcupid|bumble|badoo|un date|mon date|adopte un mec|meetic|mon ex|mon copain|ma copine|ma femme|mon mari|ma fiancée|mon fiancé(?:$|\\W)');
  20. var flair = " 🌘𝐙𝐙𝐙𝐙🌒";
  21.  
  22. window.onload = function() {
  23. if (document.getElementsByTagName("title")[0].innerHTML.includes("Forum Libre")) { //document.title non compatible avec tous les navigateurs
  24.  
  25. // Au chargement de la page, surveillance désactivée
  26. bool = 0;
  27.  
  28. // Création du bouton pour déclencher le masquage
  29. var btn = document.createElement("BUTTON");
  30. btn.innerHTML = 'Tinder <img src="https://svgur.com/i/CNH.svg" height="10px">';
  31. var zoneAjoutBtn = document.getElementsByClassName("panestack-title")[0];
  32.  
  33. btn.style.float = "right";
  34. btn.style.marginLeft = "5px";
  35. btn.style.lineHeight = "12px";
  36. btn.style.backgroundImage = "linear-gradient(to top right, #e6457c, #fb8b3e)";
  37. btn.style.borderRadius = "5px";
  38. btn.style.fontWeight = "bold";
  39. btn.style.fontFamily = "inherit";
  40.  
  41. zoneAjoutBtn.appendChild(btn);
  42.  
  43. // Lorsque bouton pressé, active la surveillance et masque certains commentaires
  44. btn.onclick = function() {
  45. if (bool == 1) {
  46. bool = 0;
  47. observer.disconnect();
  48. } else {
  49. bool = 1;
  50. surveillance();
  51. }
  52. helloTinder();
  53. }
  54. }
  55. }
  56.  
  57. // Surveillance si de nouveaux commentaires sont chargés
  58. function surveillance() {
  59. indexLastLinkMoreCmts = document.getElementsByClassName("morechildren").length - 1;
  60. targetNode = document.getElementById((document.getElementsByClassName("morechildren")[indexLastLinkMoreCmts]).id);
  61. config = { attributes: false, childList: true, subtree: true };
  62.  
  63. callback = function(mutationsList, observer) {
  64. for (var mutation of mutationsList) {
  65. if (mutation.type == 'childList') {
  66. // Si le bouton a été pressé, masque certains commentaires et reprend la surveillance
  67. if (bool == 1) {
  68. setNewObserverAndHelloTinder();
  69. }
  70. }
  71. }
  72. };
  73. observer = new MutationObserver(callback);
  74. observer.observe(targetNode, config);
  75. }
  76.  
  77. function setNewObserverAndHelloTinder() {
  78. observer.disconnect();
  79. setTimeout(function() {
  80. indexLastLinkMoreCmts = document.getElementsByClassName("morechildren").length - 1;
  81. targetNode = document.getElementById((document.getElementsByClassName("morechildren")[indexLastLinkMoreCmts]).id);
  82. helloTinder();
  83. observer = new MutationObserver(callback);
  84. observer.observe(targetNode, config);
  85. }, 1400);
  86. }
  87.  
  88. function helloTinder() {
  89. var nbComments = document.getElementsByClassName("usertext").length;
  90. var compteur;
  91.  
  92. for (compteur = 0; compteur < nbComments; compteur++) {
  93. var oneComment = document.getElementsByClassName("usertext")[compteur];
  94. var text = oneComment.parentElement.innerHTML.toLowerCase();
  95.  
  96. // N'agit que sur les top commentaires
  97. if (!text.includes('data-event-action="parent"')) {
  98.  
  99. // Si bouton a été pressé (et donc la surveillance activée), replie certains commentaires
  100. if (bool == 1) {
  101. if (text.search(regex) === -1) {
  102. oneComment.parentElement.parentElement.classList.replace("noncollapsed", "collapsed");
  103.  
  104. // Evite d'afficher le flair plusieurs fois de suite sur le même commentaire lors de chargements
  105. if (oneComment.previousSibling != null && !oneComment.previousSibling.innerHTML.includes(flair)) {
  106. oneComment.previousSibling.append(flair);
  107. }
  108. }
  109. }
  110.  
  111. // Si bouton re-pressé, rétablit l'état précédent des commentaires
  112. else {
  113. if (oneComment.previousSibling != null && oneComment.previousSibling.innerHTML.includes(flair)) {
  114. oneComment.parentElement.parentElement.classList.replace("collapsed", "noncollapsed");
  115. }
  116. }
  117. }
  118. }
  119. }