Skip to content

Instantly share code, notes, and snippets.

@devinacker
Last active November 10, 2018 02:56
Show Gist options
  • Select an option

  • Save devinacker/92211403b3674487218a07bafcfb0907 to your computer and use it in GitHub Desktop.

Select an option

Save devinacker/92211403b3674487218a07bafcfb0907 to your computer and use it in GitHub Desktop.

Revisions

  1. devinacker revised this gist Oct 4, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mastothing.user.js
    Original file line number Diff line number Diff line change
    @@ -54,7 +54,7 @@
    var itemlist = node.getElementsByClassName("item-list")[0];
    if (itemlist == null) return;

    delete node._statusObserver;
    delete itemlist._statusObserver;
    }
    });
    });
  2. devinacker revised this gist Oct 4, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mastothing.user.js
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    // @description keep timeline from automatically scrolling under mouse cursor
    // @author @revenant@mastodon.social
    // @version 0.1
    // @match https://mastodon.social/*
    // @include https://mastodon.social/*
    // @run-at document-idle
    // @namespace revenant.mastodon
    // ==/UserScript==
  3. devinacker revised this gist Oct 4, 2018. 1 changed file with 15 additions and 22 deletions.
    37 changes: 15 additions & 22 deletions mastothing.user.js
    Original file line number Diff line number Diff line change
    @@ -14,55 +14,48 @@
    // watch for added/removed child nodes for selected nodes and all child nodes
    var observerInit = { childList: true, subtree: true };

    // callback for when a status (or something else) is added to a timeline
    // callback for when a status (or something else) is added to a timeline
    var columnModified = function(recs) {
    recs.forEach(function (rec) {
    // keep the timeline scrolled down to the same spot
    var scrollable = rec.target.closest(".scrollable");
    // keep the timeline scrolled down to the same spot
    var scrollable = rec.target.closest(".scrollable");
    if (scrollable !== null && scrollable.scrollTop === 0) {
    rec.addedNodes.forEach(function(node) {
    // console.log("scroll height updated");
    rec.addedNodes.forEach(function(node) {
    scrollable.scrollTop += node.scrollHeight;
    });
    }
    });
    };

    // watch for timelines being shown/hidden
    // watch for timelines being shown/hidden
    new MutationObserver(function(recs) {
    recs.forEach(function (rec) {
    rec.addedNodes.forEach(function (node) {
    //console.log(node.className);
    if (node.className == "column") {
    var itemlist = node.getElementsByClassName("item-list")[0];
    //console.log(itemlist);
    if (itemlist == null) return;

    //console.log("column added");
    var itemlist = node.getElementsByClassName("item-list")[0];
    if (itemlist == null) return;

    itemlist._statusObserver = new MutationObserver(columnModified);

    // monitor a timeline if the user puts the mouse over it
    // monitor a timeline if the user puts the mouse over it
    itemlist.addEventListener("mouseenter", function() {
    //console.log("mouse entered scrollable");
    itemlist._statusObserver.observe(itemlist, { childList: true });
    });
    // stop monitoring that timeline when the cursor leaves

    // stop monitoring that timeline when the cursor leaves
    itemlist.addEventListener("mouseleave", function() {
    //console.log("mouse exited scrollable");
    itemlist._statusObserver.disconnect();
    });
    }
    });

    rec.removedNodes.forEach(function (node) {
    if (node.className == "column") {
    var itemlist = node.getElementsByClassName("item-list")[0];
    if (itemlist == null) return;
    if (node.className == "column") {
    var itemlist = node.getElementsByClassName("item-list")[0];
    if (itemlist == null) return;

    console.log("column removed");
    delete node._statusObserver;
    }
    delete node._statusObserver;
    }
    });
    });
    }).observe(document.getElementsByClassName("columns-area")[0], observerInit);
  4. devinacker created this gist Oct 4, 2018.
    70 changes: 70 additions & 0 deletions mastothing.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    // ==UserScript==
    // @name Mastodon timeline thing
    // @description keep timeline from automatically scrolling under mouse cursor
    // @author @revenant@mastodon.social
    // @version 0.1
    // @match https://mastodon.social/*
    // @run-at document-idle
    // @namespace revenant.mastodon
    // ==/UserScript==

    (function () {
    "use strict";

    // watch for added/removed child nodes for selected nodes and all child nodes
    var observerInit = { childList: true, subtree: true };

    // callback for when a status (or something else) is added to a timeline
    var columnModified = function(recs) {
    recs.forEach(function (rec) {
    // keep the timeline scrolled down to the same spot
    var scrollable = rec.target.closest(".scrollable");
    if (scrollable !== null && scrollable.scrollTop === 0) {
    rec.addedNodes.forEach(function(node) {
    // console.log("scroll height updated");
    scrollable.scrollTop += node.scrollHeight;
    });
    }
    });
    };

    // watch for timelines being shown/hidden
    new MutationObserver(function(recs) {
    recs.forEach(function (rec) {
    rec.addedNodes.forEach(function (node) {
    //console.log(node.className);
    if (node.className == "column") {
    var itemlist = node.getElementsByClassName("item-list")[0];
    //console.log(itemlist);
    if (itemlist == null) return;

    //console.log("column added");

    itemlist._statusObserver = new MutationObserver(columnModified);

    // monitor a timeline if the user puts the mouse over it
    itemlist.addEventListener("mouseenter", function() {
    //console.log("mouse entered scrollable");
    itemlist._statusObserver.observe(itemlist, { childList: true });
    });
    // stop monitoring that timeline when the cursor leaves
    itemlist.addEventListener("mouseleave", function() {
    //console.log("mouse exited scrollable");
    itemlist._statusObserver.disconnect();
    });
    }
    });

    rec.removedNodes.forEach(function (node) {
    if (node.className == "column") {
    var itemlist = node.getElementsByClassName("item-list")[0];
    if (itemlist == null) return;

    console.log("column removed");
    delete node._statusObserver;
    }
    });
    });
    }).observe(document.getElementsByClassName("columns-area")[0], observerInit);

    })();