Display high resolution images on wykop.pl
目前為
// ==UserScript==
// @name Better wykop
// @namespace http://tampermonkey.net/
// @version 0.1.5
// @description Display high resolution images on wykop.pl
// @author You
// @match *://*.wykop.pl/*
// @grant none
// ==/UserScript==
function debounce(func, wait, immediate = false) {
let timeout;
return function () {
const context = this, args = arguments;
const later = function () {
timeout = null;
if (!immediate) { func.apply(context, args); }
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) { func.apply(context, args); }
};
};
const removeLowResolutionFromUrl = (url) => url
.replace(',q40', '')
.replace(',w400', '')
.replace(',w113h64', '')
.replace(',w207h139', '')
.replace(',w300h223', '')
const updateImages = () => {
console.log('łogiń')
const images = document.querySelectorAll('img');
if (images) {
images.forEach((image) => {
const src = image.getAttribute('src')
const dataOriginal = image.getAttribute('data-original')
if (!image.classList.contains('lazy')) {
image.style['max-width'] = `${image.width}px`
image.setAttribute(
src ? 'src' : 'data-original',
removeLowResolutionFromUrl(src ? src : dataOriginal || '')
)
}
})
}
}
const debouncedUpdateImages = debounce(function () {
updateImages()
}, 250);
(() => {
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
window.addEventListener('scroll', debouncedUpdateImages);
setTimeout(() => {
updateImages()
}, 500)
}
};
})()