fix injection in firefox

This commit is contained in:
Maximilian Keßler 2022-09-17 01:22:20 +02:00
parent fc18c6d448
commit 54b59eb438

View file

@ -1,16 +1,18 @@
// ==UserScript==
// @name onlinetichu.com card counter
// @version 1.0.0
// @version 1.0.2
// @description automatically count cards at onlinetichu.com
// @author kesslermaximilian
// @match *://*.onlinetichu.com/Site/Game/Table/*
// ==/UserScript==
// disable auto fold functionality completely
function injectCounter() {
if (ot.AutoFold) {
ot.$autoFold.click()
ot.$autoFold.hide()
}
var myStyles = `
#playedHigh {
position: absolute;
@ -250,6 +252,8 @@ if (!window.otc) {
window.otc = OnlineTichuCounter;
}
otc.$showRemaining.hide();
// add functionality to smartFold button
otc.$smartFold.click(function () {
otc.smartFold = !otc.smartFold;
@ -397,3 +401,21 @@ MyReviewExchange = (function() {
ot.reaction.TableState = MyTableState;
ot.reaction.Chat = MyChat;
ot.action.ExchangeCards = MyExchangeCards;
};
// Special care is to be taken to safely inject our javascript into the websiet
// without the website being able to talk back to greasemonkey
// (which would be a security problem)
// see
// https://stackoverflow.com/questions/5006460/userscripts-greasemonkey-calling-a-websites-javascript-functions
// and the excellent answer by Wayne for details on this
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // run the script
document.body.removeChild(script); // clean up
}
exec(injectCounter);