Greasy Fork

Greasy Fork is available in English.

Duolingo Auto-Follow Fix

Fixing the things Duo breaks. Auto-follow discussions upon posting either a comment or a reply. (Works for sentence discussions too.)

当前为 2017-10-25 提交的版本,查看 最新版本

// ==UserScript==
// @name         Duolingo Auto-Follow Fix
// @namespace    mog86uk-duo-autofollowfix
// @version      1.0
// @description  Fixing the things Duo breaks. Auto-follow discussions upon posting either a comment or a reply. (Works for sentence discussions too.)
// @author       mog86uk (aka. testmoogle)
// @match        https://www.duolingo.com/comment/*
// @match        https://www.duolingo.com/topic/*
// @match        https://www.duolingo.com/discussion
// @require      http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @grant        none
// @run-at       document-idle
// ==/UserScript==


jQuery.noConflict();
jQuery(document).ready(function($) {
    var toclick = 0;

    function AutoFollow() {
        //observerOfStuff.disconnect();
        $('button#watch:not(.checkmark').click();
        toclick = 0;
    }

    function Start() {
        $('button#post-comment:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('button.btn.margin-right.btn-green.post-reply:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
    }

    if (window.top == window.self) {
        var observerOfStuff = new MutationObserver(function(mutations) {
            if (/^https:\/\/www\.duolingo\.com\/comment\/*/.test(window.location.href)) {
                if (!$('button#post-comment.kupo').length && !toclick) {
                    Start();
                }
                else if (toclick) {
                    AutoFollow();
                }
            }
        });

        observerOfStuff.observe(document, {
            attributes: true,
            subtree: true
        });
    }
});



/*
        $('button#post-comment:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('button.btn.margin-right.btn-green.post-reply:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('div.discussion-main-detail button.btn.btn-custom.vote-up:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('div.discussion-main-detail button.btn.btn-custom.vote-down:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('li.discussion-comments-list-item button.btn.btn-custom.vote-up:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
        $('li.discussion-comments-list-item button.btn.btn-custom.vote-down:not(.kupo)').addClass('kupo').on('click', function() {
            toclick = 1;
            AutoFollow();
        });
*/