Last active
July 7, 2020 12:12
-
-
Save skyghis/3a74c41fd35148beeccabbd3035835f1 to your computer and use it in GitHub Desktop.
This file contains 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 Display 9GAG video control on hover | |
// @version 2.6.1 | |
// @description Show video controls on mouse hover | |
// @namespace https://gist.github.com/skyghis/3a74c41fd35148beeccabbd3035835f1 | |
// @updateURL https://gist.github.com/skyghis/3a74c41fd35148beeccabbd3035835f1/raw | |
// @match https://*9gag.com/* | |
// @icon https://9gag.com/favicon.ico | |
// @author SkyghiS | |
// @homepageURL https://gist.github.com/skyghis/3a74c41fd35148beeccabbd3035835f1 | |
// @run-at document-idle | |
// ==/UserScript== | |
function safeRemove(parent, query) { | |
if (!parent) { | |
console.log("undefined parent"); | |
} | |
const e = parent.querySelector(query); | |
if (e) { | |
e.style.display = "none"; | |
console.log("element", query ,"hidden"); | |
} else { | |
console.log("element", query ,"not found for", parent); | |
} | |
} | |
// Remove 9gag app download banner | |
safeRemove(document, ".footer"); | |
safeRemove(document, "#sidebar"); // Remove desktop side banner | |
safeRemove(document, "drawer-panel"); // Useless panel | |
const shade = document.querySelector(".shade"); | |
const drawerPanel = document.querySelector("#drawer-panel"); | |
const menu = document.querySelector(".menu"); | |
if (shade && drawerPanel) { | |
//shade.style.zIndex = -1; // Remove left panel gesture zone from over videos | |
shade.addEventListener("click", () => drawerPanel.style.zIndex = -1); | |
} | |
if (drawerPanel) { | |
drawerPanel.style.zIndex = -1; // Remove left panel shade from over videos | |
if (menu) { | |
menu.addEventListener("click", () => drawerPanel.style.zIndex = 10); | |
} | |
} | |
function changeVideo(v) { | |
v.setAttribute("data-already-changed", "true"); | |
v.setAttribute("controls", true); | |
v.removeAttribute("loop"); | |
v.parentNode.parentNode.removeAttribute("target"); | |
safeRemove(v.parentNode, "span.post-indicator.play"); // Video (Old ?) | |
safeRemove(v.parentNode, "span.post-indicator.gif"); // GIF (Old ?) | |
safeRemove(v.parentNode, "div.presenting"); // Gif/Video play button | |
safeRemove(v.parentNode, "p.length"); // Duration | |
safeRemove(v.parentNode, "div.sound-toggle"); // Video sound icon | |
v.addEventListener("play", () => { | |
safeRemove(v.parentNode, "div.presenting"); // Gif/Video play button | |
safeRemove(v.parentNode, "p.length"); // Duration | |
safeRemove(v.parentNode, "div.sound-toggle"); // Video sound icon | |
}); | |
} | |
function onDomChange() { | |
clearTimeout(timer); | |
timer = setTimeout(() => { | |
const vids = document.querySelectorAll("video:not([data-already-changed=true])"); | |
for(let i = 0; i < vids.length; ++i) { | |
changeVideo(vids[i]); | |
} | |
}, 400); | |
} | |
let timer = null; | |
onDomChange(); | |
new MutationObserver(onDomChange).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