Last active
August 26, 2019 14:03
-
-
Save maple3142/57bb7506832fc416dc0344a649448c73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Twitter test + sentineljs | |
| // @namespace maple-test | |
| // @match https://twitter.com/* | |
| // @require https://cdnjs.cloudflare.com/ajax/libs/sentinel-js/0.0.5/sentinel.umd.js | |
| // @grant none | |
| // ==/UserScript== | |
| const added=new WeakMap() | |
| function addBtn(img){ | |
| if(!img || added.get(img))return | |
| const btn=document.createElement('button') | |
| btn.onclick=()=>window.open(img.src, '_blank') | |
| btn.textContent='View Image in new tab' | |
| img.parentElement.appendChild(btn) | |
| added.set(img, true) | |
| } | |
| sentinel.on('div[aria-labelledby="modal-header"] img[src^="https://pbs.twimg"]', addBtn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Twitter test | |
| // @namespace maple-test | |
| // @match https://twitter.com/* | |
| // @grant none | |
| // ==/UserScript== | |
| const added=new WeakMap() | |
| function addBtn(img){ | |
| if(!img || added.get(img))return | |
| const btn=document.createElement('button') | |
| btn.onclick=()=>window.open(img.src, '_blank') | |
| btn.textContent='View Image in new tab' | |
| img.parentElement.appendChild(btn) | |
| added.set(img, true) | |
| } | |
| const selectModalImgs=()=>Array.from(document.querySelectorAll('div[aria-labelledby="modal-header"] img[src^="https://pbs.twimg"]')) | |
| new MutationObserver(()=>{ | |
| const imgs=selectModalImgs() | |
| if(imgs.length){ | |
| imgs.forEach(addBtn) | |
| } | |
| }).observe(document.body, {subtree:true, childList: true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment