TAMailMessageErrorFix.js

Fix an script error when writing a new message.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name            TAMailMessageErrorFix.js
// @description     Fix an script error when writing a new message.
// @author          VisiG
// @version         0.2
// @namespace       https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include         https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// ==/UserScript==

(function () {
    var TAMailMessageErrorFix_main = function () {
        function TAMailMessageErrorFix_checkIfLoaded() {
        	if (PerforceChangelist >= 443425) { // patch 16.1 
        		try {
					if (typeof qx !== 'undefined' && typeof qx.core !== 'undefined' && typeof qx.core.Init !== 'undefined') {
						try {
							for (var key in webfrontend.gui.mail.MailMessage.prototype) {
								if (webfrontend.gui.mail.MailMessage.prototype.hasOwnProperty(key) && typeof(webfrontend.gui.mail.MailMessage.prototype[key]) === 'function') {  // reduced iterations from 20K to 12K
									strFunction = webfrontend.gui.mail.MailMessage.prototype[key].toString();
									if (strFunction.indexOf("this.kids") > -1) {
                                        					keyBackup = key + "Base";
										webfrontend.gui.mail.MailMessage.prototype[keyBackup] = webfrontend.gui.mail.MailMessage.prototype[key];
                                        
                                        					var matches = strFunction.match(/var (\S*)=this\.(.*)\.getChildren/);
                                        					var arrayParent = matches[2];           
                                						 webfrontend.gui.mail.MailMessage.prototype[key] = eval('(' + 
                                                                                               'function ()' +
                                                                                               '{this.kids = this.'+arrayParent+'.getChildren();' +
                                                                                               'this.'+keyBackup+'();' +
                                                                                               '}'
                                                                                               + ')') ;
										console.log("TAMailMessageErrorFix: fixed");
										break;
									}
								}
							}
						} catch (e) {
                            				console.error("TAMailMessageErrorFix: " + e);
						}
					} else {
						window.setTimeout(TAMailMessageErrorFix_checkIfLoaded, 1000);
					}
				} catch (e) {
					console.log("TAMailMessageErrorFix_checkIfLoaded: ", e);
				}
			}
		}

		if (/commandandconquer\.com/i.test(document.domain)) {
			window.setTimeout(TAMailMessageErrorFix_checkIfLoaded, 1000);
		}
    }
    
  try {
    var script = document.createElement("script");
    script.innerHTML = "(" + TAMailMessageErrorFix_main.toString() + ")();";
    script.type = "text/javascript";
    document.getElementsByTagName("head")[0].appendChild(script);
  } catch (e) {
    console.log("TAMailMessageErrorFix: init error: ", e);
  }
  
})();