NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name f*ck imgur
// @version 0.3
// @match *://*/*
// @run-at document-start
// @grant none
// @updateURL https://openuserjs.org/meta/Ahab/fck_imgur.meta.js
// @downloadURL https://openuserjs.org/install/Ahab/fck_imgur.user.js
// @license MIT
// @author Ahab [1735214]
// ==/UserScript==
const ddg = 'https://proxy.duckduckgo.com/iu/?u='
if(window.location.href.includes('i.imgur') && !(window.location.href.includes('proxy.duckduckgo'))){
window.location = ddg+window.location.href
}
function processElement(el){
if(el.tagName === 'IMG'){
const src = el.getAttribute('src');
if(src && src.includes('i.imgur') && !src.includes('proxy.duckduckgo')){
el.setAttribute('src', ddg + src);
const link = el.closest('a');
if(link){
const href = link.getAttribute('href');
if(href && href.includes('i.imgur') && !href.includes('proxy.duckduckgo')){
link.setAttribute('href', ddg + href);
}
}
}
}
if(el.tagName === 'A'){
const href = el.getAttribute('href');
const regex = /^(?:https?:\/\/)?(?:www\.)?imgur\.com\/([A-Za-z0-9]{5,})$/;
const match = regex.exec(href);
if(href && href.includes('i.imgur') && !href.includes('proxy.duckduckgo')){
el.setAttribute('href', ddg + href);
}
if(href && match && !href.includes('proxy.duckduckgo')){
const url = ddg + `https://i.imgur.com/${match[1]}.png`;
el.setAttribute('href', url);
}
}
if (el.nodeType === 1) {
const bg = window.getComputedStyle(el).backgroundImage
if (bg && bg.includes('imgur') && !bg.includes('proxy.duckduckgo')) {
const originalUrl = bg.replace(/^url\(["']?/, '').replace(/["']?\)$/, '')
const newUrl = `url("${ddg}${originalUrl}")`
el.style.backgroundImage = newUrl;
}
}
}
const observer = new MutationObserver(mutations => {
mutations.forEach(m => {
if (m.type === 'childList'){
m.addedNodes.forEach(node => {
if(node.nodeType === 1){
if(node.tagName === 'IMG' || node.tagName === 'A'){
processElement(node);
}
node.querySelectorAll && node.querySelectorAll('img, a, [style*="background-image"]').forEach(processElement);
}
});
}
});
});
observer.observe(document.documentElement, { childList: true, subtree: true });