SHOW:
|
|
- or go back to the newest paste.
| 1 | // ==UserScript== | |
| 2 | // @name DAZ-GA-FIX | |
| 3 | // @namespace daz3d.com* | |
| 4 | // @description Replaces broken chooseVariation() script with one that catches the error | |
| 5 | // @include http://www.daz3d.com/* | |
| 6 | // @include http://daz3d.com/* | |
| 7 | - | // @version 1 |
| 7 | + | // @include https://www.daz3d.com/* |
| 8 | // @include https://daz3d.com/* | |
| 9 | // @version 2 | |
| 10 | // @grant none | |
| 11 | // @author mork | |
| 12 | // @license no restrictions besides NOMIL+NOGOV | |
| 13 | // @run-at document-start | |
| 14 | // ==/UserScript== | |
| 15 | // | |
| 16 | ||
| 17 | // v2: added includes for HTTPS | |
| 18 | ||
| 19 | // credits: http://stackoverflow.com/questions/3972038/stop-execution-of-javascript-function-client-side-or-tweak-it | |
| 20 | checkForBadJavascripts ( [ | |
| 21 | [false, /chooseVariation/, function () {addJS_Node (betterFunction);} ]
| |
| 22 | ] ); | |
| 23 | ||
| 24 | ||
| 25 | ||
| 26 | function checkForBadJavascripts (controlArray) {
| |
| 27 | /*--- Note that this is a self-initializing function. The controlArray | |
| 28 | parameter is only active for the FIRST call. After that, it is an | |
| 29 | event listener. | |
| 30 | ||
| 31 | The control array row is defines like so: | |
| 32 | [bSearchSrcAttr, identifyingRegex, callbackFunction] | |
| 33 | Where: | |
| 34 | bSearchSrcAttr True to search the SRC attribute of a script tag | |
| 35 | false to search the TEXT content of a script tag. | |
| 36 | identifyingRegex A valid regular expression that should be unique | |
| 37 | to that particular script tag. | |
| 38 | callbackFunction An optional function to execute when the script is | |
| 39 | found. Use null if not needed. | |
| 40 | */ | |
| 41 | if ( ! controlArray.length) return null; | |
| 42 | ||
| 43 | checkForBadJavascripts = function (zEvent) {
| |
| 44 | ||
| 45 | for (var J = controlArray.length - 1; J >= 0; --J) {
| |
| 46 | var bSearchSrcAttr = controlArray[J][0]; | |
| 47 | var identifyingRegex = controlArray[J][1]; | |
| 48 | ||
| 49 | if (bSearchSrcAttr) {
| |
| 50 | if (identifyingRegex.test (zEvent.target.src) ) {
| |
| 51 | stopBadJavascript (J); | |
| 52 | return false; | |
| 53 | } | |
| 54 | } | |
| 55 | else {
| |
| 56 | if (identifyingRegex.test (zEvent.target.textContent) ) {
| |
| 57 | stopBadJavascript (J); | |
| 58 | return false; | |
| 59 | } | |
| 60 | } | |
| 61 | } | |
| 62 | ||
| 63 | function stopBadJavascript (controlIndex) {
| |
| 64 | zEvent.stopPropagation (); | |
| 65 | zEvent.preventDefault (); | |
| 66 | ||
| 67 | var callbackFunction = controlArray[J][2]; | |
| 68 | if (typeof callbackFunction == "function") | |
| 69 | callbackFunction (); | |
| 70 | ||
| 71 | //--- Remove the node just to clear clutter from Firebug inspection. | |
| 72 | zEvent.target.parentNode.removeChild (zEvent.target); | |
| 73 | ||
| 74 | //--- Script is intercepted, remove it from the list. | |
| 75 | controlArray.splice (J, 1); | |
| 76 | if ( ! controlArray.length) {
| |
| 77 | //--- All done, remove the listener. | |
| 78 | window.removeEventListener ( | |
| 79 | 'beforescriptexecute', checkForBadJavascripts, true | |
| 80 | ); | |
| 81 | } | |
| 82 | } | |
| 83 | } | |
| 84 | ||
| 85 | /*--- Use the "beforescriptexecute" event to monitor scipts as they are loaded. | |
| 86 | See https://developer.mozilla.org/en/DOM/element.onbeforescriptexecute | |
| 87 | Note that it does not work on acripts that are dynamically created. | |
| 88 | */ | |
| 89 | window.addEventListener ('beforescriptexecute', checkForBadJavascripts, true);
| |
| 90 | ||
| 91 | return checkForBadJavascripts; | |
| 92 | } | |
| 93 | ||
| 94 | ||
| 95 | function betterFunction() {
| |
| 96 | var doorNumber = 0; | |
| 97 | try {
| |
| 98 | doorNumber = cxApi.chooseVariation(); | |
| 99 | if (typeof doorNumber != 'number') {
| |
| 100 | //console.log("doorNumber is not a number. Set to 0");
| |
| 101 | doorNumber = 0; | |
| 102 | } | |
| 103 | } catch (e) {}
| |
| 104 | ||
| 105 | $(document).ready(function() {
| |
| 106 | var bodyElem = document.getElementsByTagName('body')[0];
| |
| 107 | bodyElem.className = bodyElem.className + " door_number_"+doorNumber; | |
| 108 | }); | |
| 109 | } | |
| 110 | ||
| 111 | ||
| 112 | ||
| 113 | function addJS_Node (text, s_URL, funcToRun) {
| |
| 114 | var D = document; | |
| 115 | var scriptNode = D.createElement ('script');
| |
| 116 | scriptNode.type = "text/javascript"; | |
| 117 | if (text) scriptNode.textContent = text; | |
| 118 | if (s_URL) scriptNode.src = s_URL; | |
| 119 | if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
| |
| 120 | ||
| 121 | var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
| |
| 122 | //--- Don't error check here. if DOM not available, should throw error. | |
| 123 | targ.appendChild (scriptNode); | |
| 124 | } |