Reddit FL - Bye Tinder

Cache les top-comments qui parlent de Tinder sur le FL de /r/france (Old Reddit).

目前為 2019-04-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Reddit FL - Bye Tinder
// @author       RandomUsername404
// @namespace    https://greasyfork.org/en/users/105361-randomusername404
// @version      0.2
// @description  Cache les top-comments qui parlent de Tinder sur le FL de /r/france (Old Reddit).
// @run-at       document-start
// @include      https://old.reddit.com/r/france/*
// @grant        none
// @icon         https://i.imgtc.com/Fz9pURU.png
// ==/UserScript==

var numLienLoad;
var targetNode;
var config;
var callback;
var observer;

window.onload = function() {
    if (document.getElementsByTagName("title")[0].innerHTML.includes("Forum Libre")) { //document.title non compatible avec tous les navigateurs
        byeTinder();

        // Surveillance si de nouveaux commentaires sont chargés
        numLienLoad = document.getElementsByClassName("morechildren").length - 1;
        targetNode = document.getElementById((document.getElementsByClassName("morechildren")[numLienLoad]).id);
        config = { attributes: false, childList: true, subtree: true };

        callback = function(mutationsList, observer) {
            for (var mutation of mutationsList) {
                if (mutation.type == 'childList') {
                    setNewObserverAndByeTinder();
                }
            }
        };
        observer = new MutationObserver(callback);
        observer.observe(targetNode, config);
    }
}

function setNewObserverAndByeTinder() {
    observer.disconnect();
    setTimeout(function() {
        numLienLoad = document.getElementsByClassName("morechildren").length - 1;
        targetNode = document.getElementById((document.getElementsByClassName("morechildren")[numLienLoad]).id);
        byeTinder();
        observer = new MutationObserver(callback);
        observer.observe(targetNode, config);
    }, 450);
}

function byeTinder() {
    var nbComments = document.getElementsByClassName("usertext").length;
    var compteur;
    var flair = " 💗𝐓𝐈𝐍𝐃𝐄𝐑💗";

    for (compteur = 0; compteur < nbComments; compteur++) {
        var oneComment = document.getElementsByClassName("usertext")[compteur];
        var text = document.getElementById(oneComment.id).parentElement.innerHTML;

        // N'agit que sur les top commentaires
        if (!text.includes('data-event-action="parent"')) {
            if (text.includes("Tinder") || text.includes("tinder")) {
                oneComment.parentElement.parentElement.classList.replace("noncollapsed", "collapsed");

                // Evite d'afficher le flair plusieurs fois de suite sur le même commentaire lors de chargements
                if (!oneComment.previousSibling.innerHTML.includes(flair)) {
                    oneComment.previousSibling.append(flair);
                }
            }
        }
    }
}