Mercurial > ec-userscripts
diff tweetdeck-large-image.user.js @ 85:9c8cde985caf
Update standard and fix
author | nanaya <me@nanaya.pro> |
---|---|
date | Thu, 15 Apr 2021 15:01:22 +0900 |
parents | 86da34e62d29 |
children | 2c4470b73ad9 |
line wrap: on
line diff
--- a/tweetdeck-large-image.user.js Thu Apr 15 14:56:23 2021 +0900 +++ b/tweetdeck-large-image.user.js Thu Apr 15 15:01:22 2021 +0900 @@ -12,26 +12,7 @@ ;(function () { 'use strict' - // loop through passed nodes (or body if called without arguments) - var run = function (nodes) { - if (nodes == null) { - nodes = [document.body] - } - - for (var i = 0; i < nodes.length; i++) { - // first try fixing itself - fix(nodes[i]) - - // and then find all the links inside - var links = nodes[i].querySelectorAll('.js-media-image-link') - - for (var j = 0; j < links.length; j++) { - fix(links[j]) - } - } - } - - var fix = function (link) { + const fix = function (link) { // basic sanity check if (!link.classList.contains('js-media-image-link')) { return @@ -43,8 +24,8 @@ } link._ecUserscript = true - var image = link.querySelector('.media-img') - var url + const image = link.querySelector('.media-img') + let url // sometimes the image is just background image of the link. // strip all query strings and original :size suffix @@ -54,7 +35,7 @@ url = image.src } - var parsedUrl = new URL(url) + const parsedUrl = new URL(url) if (parsedUrl.searchParams.get('name') == null) { url = url.replace(/(\..+:).+/, '$1orig') @@ -69,14 +50,33 @@ link.setAttribute('href', url) } - var onMutate = function (mutations) { - for (var mutation in mutations) { + // loop through passed nodes (or body if called without arguments) + const run = function (nodes) { + if (nodes == null) { + nodes = [document.body] + } + + for (let i = 0; i < nodes.length; i++) { + // first try fixing itself + fix(nodes[i]) + + // and then find all the links inside + const links = nodes[i].querySelectorAll('.js-media-image-link') + + for (let j = 0; j < links.length; j++) { + fix(links[j]) + } + } + } + + const onMutate = function (mutations) { + for (const mutation in mutations) { run(mutation.addedNodes) } } // the observer - var observer = new window.MutationObserver(onMutate) + const observer = new window.MutationObserver(onMutate) // start the observer observer.observe(document, { childList: true, subtree: true })