Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Happo-YLE
- // @namespace ylefi
- // @description Onnellisempia uutisia.
- // @include http://yle.fi/*
- // @version 1
- // @grant none
- // ==/UserScript==
- (($) => {
- let swap = function (image, attrName) {
- let old = image.getAttribute(attrName);
- if (old) {
- image.setAttribute(attrName, old.replace(/image\/upload\/\/?([^\/]+?)\//, (match, params) => {
- return `image/upload/${params},e_saturation:9001/`
- }));
- }
- }
- let process = (node) => {
- let container = $(node)
- container.find('[src*="image/upload"]').each((i, image) => {
- if ($(image).attr('hapokas')) return
- swap(image, 'src');
- $(image).attr('hapokas', true)
- })
- container.find('[content*="image/upload"], [data-src*="image/upload"]').each((i, image) => {
- if ($(image).attr('hapokas')) return
- swap(image, 'data-src')
- swap(image, 'content')
- $(image).attr('hapokas', true)
- })
- }
- var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- if (!mutation.addedNodes) return
- if ($(mutation.target).is('img') && mutation.attributeName == 'data-src') {
- console.log(mutation.target);
- process($(mutation.target).parent())
- }
- if ($(mutation.target).is('img') && mutation.attributeName == 'src') {
- console.log(mutation.target);
- process($(mutation.target).parent())
- }
- mutation.addedNodes.forEach(process)
- })
- })
- observer.observe(document.body, {
- childList: true
- , subtree: true
- , attributes: true
- , characterData: false
- })
- process($('body'))
- })(window.jQuery);
Add Comment
Please, Sign In to add comment