Jump to content

User:Bradv/Scripts/linktocomment.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function( $, mw ) {
    'use strict';

    mw.util.addCSS(`
        a.linktocomment img {
            height: 0.8em;
            filter: opacity(0.5);
        }
        a.linktocomment img:hover {
            filter: unset;
        }
    `)

    $('span[data-mw-comment-end]').each(function () {
        let span = $(this);
        if (span.parents('.mw-headline').length == 0) {
            $('<a>', {'class': 'linktocomment', 'href':'#' + span.attr('data-mw-comment-end')})
                .append($('<img>', {'src': 'https://upload.wikimedia.org/wikipedia/commons/5/56/Chain_link_icon_slanted.png'}))
                .insertAfter(span);
        }
    })

}(jQuery, mediaWiki ));