Last active
February 16, 2020 14:06
-
-
Save nicholastay/46eefd26373684785dc5a1cf18a00abd to your computer and use it in GitHub Desktop.
op.gg copy/paste command for spectate
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 op.gg spectate override | |
// @namespace http://nicholastay.github.io/ | |
// @version 0.1.1 | |
// @author Nicholas Tay | |
// @license MIT | |
// @match *://*op.gg/* | |
// @grant none | |
// ==/UserScript== | |
var LEAGUE_PATH = 'D:\\Games\\Riot Games\\League of Legends'; | |
var LEAGUE_LOCALE = 'ko_KR'; | |
function spectateOverride(gameId) { | |
// Most taken from default | |
$.OP.GG.util.blockBodyScroll(function(end){ | |
$.OP.GG.common.dim({ | |
onClose: function(){ | |
end(); | |
}, | |
job: function(setHTML, doClose){ | |
$.OP.GG.ajax.getHTML({ | |
url: '/match/new/', | |
async: false, // required for firefox to count as click-handler for copy clipboard | |
data: { | |
id: gameId | |
}, | |
callback: { | |
onHTML: function(html){ | |
//setHTML(html); | |
spectateCallback(html, doClose); | |
}, | |
onError: function(error){ | |
alert(error); | |
doClose(); | |
} | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
// Our override | |
function spectateCallback(html, doClose) { | |
// Take HTML run path | |
var run = $('.Spectate-Mac textarea', html).text(); | |
// Clean it up | |
run = run.split('&&'); | |
run = run[run.length-1]; // Last command in line | |
run = run.substring(run.indexOf('"')); // Only the command | |
// Settings | |
run = run.replace(/-Locale=(.*?)"/, '-Locale=' + LEAGUE_LOCALE + '"'); | |
run = '"' + LEAGUE_PATH + '\\Game\\League of Legends.exe" ' + run; | |
// Replace elem with launch line, then copy it | |
var elem = document.querySelector('.SpectatorButtons a[onclick*="openSpectate"]'); | |
if (!elem || elem.length < 1) { | |
prompt('Copy the following run line to spectate!', run); | |
} else { | |
var inp = document.createElement('input'); | |
inp.type = 'text'; | |
inp.setAttribute('value', run); | |
inp.readOnly = true; | |
inp.style = 'width:275px;height:25px;font-size:9pt;'; | |
elem.replaceWith(inp); | |
inp.select(); | |
document.execCommand('copy'); | |
} | |
doClose(); | |
} | |
// Override it | |
$.OP.GG.matches.openSpectate = spectateOverride; | |
console.log("op.gg quick spectate injected"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment