From f82c73dd3bc8749c828b67b0c4ecd13eb9b042ec Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 25 Jan 2015 01:45:12 -0500 Subject: [PATCH] Fix links to PS rooms Clicking links to PS rooms can be pretty unreliable in terms of whether and where they open. This commit uses a global click handler, to make sure that any and every link to PS rooms, including links in the News, will open in the current PS window. You can always right-click and Open in New Tab, of course. --- js/client.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/js/client.js b/js/client.js index b4844e268..4b22830e4 100644 --- a/js/client.js +++ b/js/client.js @@ -2,16 +2,31 @@ if (window.nodewebkit) { window.gui = require('nw.gui'); - $('body').on('click', 'a', function(e) { - if (this.target === '_blank') { - gui.Shell.openExternal(this.href); + window.nwWindow = gui.Window.get(); + } + $(document).on('click', 'a', function(e) { + if (this.href && this.className !== 'closebutton' && (this.href.substr(0, 32) === 'http://play.pokemonshowdown.com/' || this.href.substr(0, 33) === 'https://play.pokemonshowdown.com/')) { + var target; + if (this.href.charAt(4) === ':') { + target = this.href.substr(32); + } else { + target = this.href.substr(33); + } + if (target.indexOf('/') < 0 && target.indexOf('.') < 0) { + window.app.tryJoinRoom(target); e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); + return; } - }); - window.nwWindow = gui.Window.get(); - } + } + if (window.nodewebkit && this.target === '_blank') { + gui.Shell.openExternal(this.href); + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + } + }); Config.version = '0.9.2'; Config.origindomain = 'play.pokemonshowdown.com';