Metafilter MultiFavorited Multiwidth for Safari?
July 7, 2024 5:44 PM   Subscribe

I'm addicted to Chrome's Metafilter MultiFavorited Multiwidth extension. I'd really like (for various reasons I don't need to go into here) to switch to Safari, and it's one of the only things holding me back. The original greasemonkey script no longer works (or at least, it doesn't work in Safari's Tampermonkey). Help?
posted by dmd to Computers & Internet (2 answers total) 2 users marked this as a favorite
 
Best answer: I had to make a few changes, but I was able to get the script to work in Firefox. Does this updates script work for you?

// ==UserScript==
// @name          Metafilter MultiFavorited Multiwidth - November Experiment
// @namespace     http://www.example.com
// @description   Code adjusted to deal with the "November Experiment"
// @match         *://www.metafilter.com/*
// @match         *://*.metafilter.com/*
// @grant         none
// @version       1.0
// ==/UserScript==

(function () {
    'use strict';

    // Threshold; at this number or higher the comment will be highlighted
    const threshold = 2;

    // Highlighting colors, change to match your preferences!
    const MetaHighlight = '#337dc3';
    const askMeHighlight = '#47cf4a';
    const TalkHighlight = '#888888';

    const searchPattern = "//a[contains(@title,'marked this as favorite')]";

    // Function to highlight comments based on favorite counts
    const highlightComments = () => {
        const options = document.evaluate(searchPattern, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        for (let i = 0; i < options.snapshotLength; i++) {
            const klass = options.snapshotItem(i);
            const favCount = parseInt(klass.title.replace(/^[^0-9]*([0-9]+)[^0-9]+$/, '$1'), 10);

            if (favCount >= threshold) {
                let commentNode = klass;
                while (commentNode.nodeName !== "DIV") {
                    commentNode = commentNode.parentNode;
                }

                if (commentNode) {
                    commentNode.style.borderLeft = `${(favCount / 2) + 1}px solid`;
                    commentNode.style.paddingLeft = '5px';
                    commentNode.style.marginLeft = `${70 - ((favCount / 2) + 1)}px`;

                    if (document.location.hostname.startsWith('www')) {
                        commentNode.style.borderColor = MetaHighlight;
                    }
                    if (document.location.hostname.startsWith('ask')) {
                        commentNode.style.borderColor = askMeHighlight;
                    }
                    if (document.location.hostname.startsWith('metatalk')) {
                        commentNode.style.borderColor = TalkHighlight;
                    }
                }
            }
        }
    };

    highlightComments();
})();

posted by phil at 6:57 PM on July 7, 2024 [3 favorites]


Response by poster: Yes, thank you!
posted by dmd at 4:43 AM on July 8, 2024


« Older Should I eat this?   |   Where (else) should I stay in Quebec City? Newer »

You are not logged in, either login or create an account to post comments