Skip to content

Instantly share code, notes, and snippets.

@psenough
Last active June 25, 2023 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psenough/6b2961eb086542c86f134750486da1a8 to your computer and use it in GitHub Desktop.
Save psenough/6b2961eb086542c86f134750486da1a8 to your computer and use it in GitHub Desktop.
Fix some usability things on warzone
// ==UserScript==
// @name Fix Warlight
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to make warzone a little more playable
// @author ps
// @match https://www.warzone.com/MultiPlayer?GameID=*
// @icon https://www.google.com/s2/favicons?sz=64&domain=warzone.com
// @grant none
// ==/UserScript==
function tryToHookLiveWorld() {
//console.log("trying to hook");
let myDiv = document.querySelector("#ujs_LiveWorldRoot");
if (myDiv) {
myDiv.addEventListener("click", capture, false);
} else {
setTimeout(tryToHookLiveWorld, 1000);
}
}
function capture(){
//console.log("click");
setTimeout(function() {
let mdom = document.querySelectorAll(`[id*="ujs_MapInspectorOverlay_"]`);
if (mdom.length != 0) {
let mi=mdom[0];
// the map where the gui is hidden is unclickable
// guess the click area is calculated on the canvas layer internally
mi.style="display: none;";
// make tooltip see-through
let op = mdom[0].parentNode.children[4];
op.style="opacity: 0.1;";
recover(op);
} else {
//console.log("no MapInspector found");
}
}, 60);
}
function recover(op){
let ttop = op;
setTimeout(function(){
// fade in tool tip
ttop.style="opacity: 1; transition: opacity 1.0s ease-in-out;";
// simulate a click to close the invisible gui
// we dont do it earlier because we want to see the arrows
//let mbtn = tmi.querySelectorAll(`[id*="ujs_CloseBtn_"]`);
let mbtn = document.querySelectorAll(`a[id*="ujs_CloseBtn_"]`);
//console.log(mbtn);
if (mbtn.length >= 3) {
mbtn[2].click();
}
}, 600);
}
(function() {
//'use strict';
console.log("Fixing warlight with a script");
// prevent text selection on the whole page
// something that often occurs by mistake when the turn happens while you're clicking things
document.documentElement.style = "user-select: none;"
// try to hook a click function on LiveWorldRoot that suppresses the MapInspectorOverlay popup
// because it's only useful for people who don't know the map
// and incredibly annoying for people who already know the map and can see the bonuses highlighted
tryToHookLiveWorld();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment