Mercurial > ec-userscripts
diff tweetdeck-large-image.user.js @ 66:444b17e657be
Standardize code style
author | nanaya <me@nanaya.pro> |
---|---|
date | Wed, 10 Jul 2019 22:36:31 +0900 |
parents | 6715e53ad0bf |
children | f03e2d169a8a |
line wrap: on
line diff
--- a/tweetdeck-large-image.user.js Wed Jul 10 22:30:14 2019 +0900 +++ b/tweetdeck-large-image.user.js Wed Jul 10 22:36:31 2019 +0900 @@ -9,76 +9,75 @@ // @downloadURL https://bitbucket.org/nanayapro/ec-userscripts/raw/tip/tweetdeck-large-image.user.js // ==/UserScript== -;(function() { - "use strict"; +;(function () { + 'use strict' // loop through passed nodes (or body if called without arguments) - var run = function(nodes) { + var run = function (nodes) { if (nodes == null) { - nodes = [document.body]; + nodes = [document.body] } for (var i = 0; i < nodes.length; i++) { // first try fixing itself - fix(nodes[i]); + fix(nodes[i]) // and then find all the links inside - var links = nodes[i].querySelectorAll(".js-media-image-link"); + var links = nodes[i].querySelectorAll('.js-media-image-link') for (var j = 0; j < links.length; j++) { - fix(links[j]); + fix(links[j]) } } - }; + } - var fix = function(link) { + var fix = function (link) { // basic sanity check - if (!link.classList.contains("js-media-image-link")) { - return; + if (!link.classList.contains('js-media-image-link')) { + return } // don't run again if already run on passed link if (link._ecUserscript) { - return; + return } - link._ecUserscript = true; + link._ecUserscript = true - var image = link.querySelector(".media-img"); - var url; + var image = link.querySelector('.media-img') + var url // sometimes the image is just background image of the link. // strip all query strings and original :size suffix if (image == null) { - url = getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)\1\)$/, "$2"); + url = window.getComputedStyle(link).backgroundImage.replace(/^url\(('|")?(.+?)\1\)$/, '$2') } else { - url = image.src; + url = image.src } - var parsedUrl = new URL(url); + var parsedUrl = new URL(url) if (parsedUrl.searchParams.get('name') == null) { - url = url.replace(/(\..+:).+/, "$1orig"); + url = url.replace(/(\..+:).+/, '$1orig') } else { - parsedUrl.searchParams.delete('format'); - parsedUrl.searchParams.set('name', 'orig'); - url = parsedUrl.href; + parsedUrl.searchParams.delete('format') + parsedUrl.searchParams.set('name', 'orig') + url = parsedUrl.href } - link.setAttribute("href", url); - - }; + link.setAttribute('href', url) + } - var onMutate = function(mutations) { + var onMutate = function (mutations) { for (var mutation in mutations) { - run(mutation.addedNodes); + run(mutation.addedNodes) } - }; + } // the observer - var observer = new MutationObserver(onMutate); + var observer = new window.MutationObserver(onMutate) // start the observer - observer.observe(document, { childList: true, subtree: true}); + observer.observe(document, { childList: true, subtree: true }) // initial run on existing document - run(); -}).call(); + run() +}).call()