SHOW:
|
|
- or go back to the newest paste.
1 | // ==UserScript== | |
2 | // @name Happo-YLE | |
3 | // @namespace ylefi | |
4 | // @description Onnellisempia uutisia. | |
5 | // @include http://yle.fi/* | |
6 | // @version 1 | |
7 | // @grant none | |
8 | // ==/UserScript== | |
9 | ||
10 | (($) => { | |
11 | let swap = function (image, attrName) { | |
12 | let old = image.getAttribute(attrName); | |
13 | if (old) { | |
14 | image.setAttribute(attrName, old.replace(/image\/upload\/\/?([^\/]+?)\//, (match, params) => { | |
15 | return `image/upload/${params},e_saturation:9001/` | |
16 | })); | |
17 | } | |
18 | } | |
19 | ||
20 | let process = (node) => { | |
21 | let container = $(node) | |
22 | container.find('[src*="image/upload"]').each((i, image) => { | |
23 | if ($(image).attr('hapokas')) return | |
24 | - | swap(image, 'src'); |
24 | + | swap(image, 'src') |
25 | $(image).attr('hapokas', true) | |
26 | }) | |
27 | container.find('[content*="image/upload"], [data-src*="image/upload"]').each((i, image) => { | |
28 | if ($(image).attr('hapokas')) return | |
29 | swap(image, 'data-src') | |
30 | swap(image, 'content') | |
31 | $(image).attr('hapokas', true) | |
32 | }) | |
33 | } | |
34 | ||
35 | var observer = new MutationObserver(function(mutations) { | |
36 | mutations.forEach(function(mutation) { | |
37 | if (!mutation.addedNodes) return | |
38 | - | |
38 | + | if ($(mutation.target).is('img') && (mutation.attributeName == 'data-src' || mutation.attributeName == 'src')) { |
39 | - | if ($(mutation.target).is('img') && mutation.attributeName == 'data-src') { |
39 | + | |
40 | - | console.log(mutation.target); |
40 | + | |
41 | mutation.addedNodes.forEach(process) | |
42 | }) | |
43 | - | if ($(mutation.target).is('img') && mutation.attributeName == 'src') { |
43 | + | |
44 | - | console.log(mutation.target); |
44 | + | |
45 | observer.observe(document.body, { | |
46 | childList: true, | |
47 | subtree: true, | |
48 | attributes: true, | |
49 | characterData: false | |
50 | }) | |
51 | ||
52 | - | childList: true |
52 | + | |
53 | - | , subtree: true |
53 | + | |
54 | - | , attributes: true |
54 | + |