Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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')
  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.         if ($(mutation.target).is('img') && (mutation.attributeName == 'data-src' || mutation.attributeName == 'src')) {
  39.             process($(mutation.target).parent())
  40.         }
  41.         mutation.addedNodes.forEach(process)
  42.       })
  43.     })
  44.  
  45.     observer.observe(document.body, {
  46.       childList: true,
  47.       subtree: true,
  48.       attributes: true,
  49.       characterData: false
  50.     })
  51.    
  52.     process($('body'))
  53.    
  54. })(window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement