Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greasemonkey/firefox 58 compability #1249

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ window.iitcBuildDate = '@@BUILDDATE@@';
window.onload = function() {};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have the same problem here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like:
unsafeWindow.onload = exportFunction(function() {}, unsafeWindow);

Copy link

@Jormund Jormund Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested on Greasemonkey on FF and Tampermonkey on Chrome. I don't think setting window.onload had any use, it has already run at this point. With GM4.0 it isn't assigning the correct "window.onload". It doesn't fail and has no effect since it is not used anyway.

A way to do this is and stay compatible with different extensions and browsers is:

if(typeof exportFunction == "function")
	exportFunction(function() {}, window, {defineAs:'onload'});
else if(typeof window.wrappedJSObject == "object")
	window.wrappedJSObject.onload = function() {};
else
	window.onload = function() {};

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. That's logically dead code, as is the document.body.onload just below it (introduced by 98f6f19) since document.body as a whole is replaced.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine, great job!

document.body.onload = function() {};


//originally code here parsed the <Script> tags from the page to find the one that defined the PLAYER object
//however, that's already been executed, so we can just access PLAYER - no messing around needed!

if (typeof(window.PLAYER)!="object" || typeof(window.PLAYER.nickname) != "string") {
var PLAYER = window.PLAYER || window.wrappedJSObject.PLAYER;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just be unsafeWindow in either case

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure window.wrappedJSObject exist in all contexts that run IITC ?

Another way to write the test is

if (!((typeof(window.PLAYER)=="object" && typeof(window.PLAYER.nickname) == "string") 
	||(typeof(window.wrappedJSObject)=="object" && typeof(window.wrappedJSObject.PLAYER)=="object" && typeof(window.wrappedJSObject.PLAYER.nickname) == "string"))){
  // page doesn’t have a script tag with player information.
  if(document.getElementById('header_email')) {
    // however, we are logged in.
    // it used to be regularly common to get temporary 'account not enabled' messages from the intel site.
    // however, this is no longer common. more common is users getting account suspended/banned - and this
    // currently shows the 'not enabled' message. so it's safer to not repeatedly reload in this case
//    setTimeout('location.reload();', 3*1000);
    throw("Page doesn't have player data, but you are logged in.");
  }
  // FIXME: handle nia takedown in progress
  throw("Couldn't retrieve player data. Are you logged in?");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jormund oh, yes, it needs an extra test for wappedJSObject for TM

if (typeof(PLAYER)!="object" || typeof(PLAYER.nickname) != "string") {
// page doesn’t have a script tag with player information.
if(document.getElementById('header_email')) {
// however, we are logged in.
Expand All @@ -45,7 +45,6 @@ if (typeof(window.PLAYER)!="object" || typeof(window.PLAYER.nickname) != "string
throw("Couldn't retrieve player data. Are you logged in?");
}


// player information is now available in a hash like this:
// window.PLAYER = {"ap": "123", "energy": 123, "available_invites": 123, "nickname": "somenick", "team": "ENLIGHTENED||RESISTANCE"};

Expand Down