Skip to content

Commit

Permalink
1. Fix new tab's window.opener when click BBS view anchor tag.
Browse files Browse the repository at this point in the history
2. Fix framescript update issue.
  • Loading branch information
ettoolong committed Sep 14, 2016
1 parent ccceb94 commit c4787d0
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 62 deletions.
42 changes: 35 additions & 7 deletions chrome/content/bbsfox.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,17 +828,21 @@ BBSFox.prototype={
//this.loadLoginData();
},

setFrameScript: function(cb) {
setFrameScript: function(cb, init) {
if(!this.FrameScriptCb) {
//Update Overlay Prefs and Event Prefs
this.FrameScriptCb = cb;
if(this.prefs) {
this.prefs.updateEventPrefs(); //force update
this.loadLoginData();
} else {
if(init) {
//Update Overlay Prefs and Event Prefs
this.FrameScriptCb = cb;
if(this.prefs) {
this.prefs.updateEventPrefs(); //force update
this.loadLoginData();
}
}
return true;
} else {
if(this.FrameScriptCb !== cb) {
this.sendCoreCommand({command: "disableScript"});
}
this.FrameScriptCb = cb;
this.prefs.updateEventPrefs(); //force update
this.sendCoreCommand({command: "updateTabIcon", icon: this.prefs.status.tabIcon});
Expand Down Expand Up @@ -1133,6 +1137,7 @@ BBSFox.prototype={
}
if(event.target && event.target.getAttribute("link")=='true') //TODO: check target type.
{
var defaultAction = true;
//try to find out ancher node and get boardName.
//if boardName == current boardname, jump to other board
if(this.prefs.aidAction!=0 && this.prefs.aidAction!=1) {
Expand All @@ -1159,11 +1164,16 @@ BBSFox.prototype={
this.conn.send(sendCode);
event.stopPropagation();
event.preventDefault();
defaultAction = false;
}
}
} else if(this.prefs.aidAction==1 && this.prefs.loadURLInBG){
defaultAction = false;
this.bgtab(event);
}
if(defaultAction){
this.fgtab(event);
}
return;
}
if(window.getSelection().isCollapsed) //no anything be select
Expand Down Expand Up @@ -1787,6 +1797,24 @@ BBSFox.prototype={
}
},

fgtab: function (event){
if(event.target && event.target.getAttribute("link")=='true') {
var aNode = event.target;
if(aNode.parentNode && aNode.parentNode.nodeName == 'A') {
aNode = aNode.parentNode;
} else if(aNode.parentNode && aNode.parentNode.parentNode && aNode.parentNode.parentNode.nodeName == 'A') {
aNode = aNode.parentNode.parentNode;
} else {
aNode = null;
}
if(aNode) {
this.sendCoreCommand({command: "openNewTabs", charset: this.prefs.charset, ref: null, loadInBg: false, urls:[aNode.href]}, true);
event.stopPropagation();
event.preventDefault();
}
}
},

bgtab: function (event){
if(this.prefs.loadURLInBG)
{
Expand Down
127 changes: 73 additions & 54 deletions chrome/content/bbsfox_frame_script.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,84 @@
//fire event from bbsfox overlay

const { utils: Cu, classes: Cc, interfaces: Ci, manager: Cm, results: Cr } = Components;
addMessageListener("bbsfox@ettoolong:bbsfox-overlayCommand",
function(message) {

let enabled = true;
function handleOverlayCommand(message) {
if(!enabled) return;
if(content) {
let bbscore = content.bbsfox;
if(bbscore) {
bbscore.overlaycmd.exec(message.data);
}
}
}

function handleAddonCommand(message) {
if(!enabled) return;
//console.log(message.data.command);
let doRefreshTabs = function(doc, close) {
let loc = doc.location;
let protocol = loc.protocol.toLowerCase();
if (protocol == "telnet:" || protocol == "ssh:") {
// Disconnect page.
} else if(loc.href == "about:bbsfox"){
content.close();
}
};
if(content) {
switch (message.data.command) {
case "disable":
case "uninstall":
doRefreshTabs(content.document, true);
break;
case "startup":
case "enable":
case "install":
case "upgrade":
case "downgrade":
doRefreshTabs(content.document, false);
break;
default:
break;
}
}
}

function handleOverlayEvent(message) {
if(!enabled) return;
if(message.data.command === "update") {
if(content) {
let bbscore = content.bbsfox;
if(bbscore) {
bbscore.overlaycmd.exec(message.data);
bbscore.updateTabInfo();
}
}
}
);
}

addMessageListener("bbsfox@ettoolong:bbsfox-addonCommand",
function(message) {
//console.log(message.data.command);
let doRefreshTabs = function(doc, close) {
let loc = doc.location;
let protocol = loc.protocol.toLowerCase();
if (protocol == "telnet:" || protocol == "ssh:") {
// Disconnect page.
} else if(loc.href == "about:bbsfox"){
content.close();
}
};
if(content) {
switch (message.data.command) {
case "disable":
case "uninstall":
doRefreshTabs(content.document, true);
break;
case "startup":
case "enable":
case "install":
case "upgrade":
case "downgrade":
doRefreshTabs(content.document, false);
break;
default:
break;
}
}
function frameScript(message, async){
if(message.command === "disableScript") {
enabled = false;
removeEventListener("bbsfox@ettoolong:bbsfox-overlayCommand", handleOverlayCommand, false);
removeEventListener("bbsfox@ettoolong:bbsfox-addonCommand", handleAddonCommand, false);
removeEventListener("bbsfox@ettoolong:bbsfox-overlayEvent", handleOverlayEvent, false);
} else {
if(!async)
return sendSyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", message);
else
return sendAsyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", message);
}
);
}

addMessageListener("bbsfox@ettoolong:bbsfox-overlayCommand", handleOverlayCommand, false);
addMessageListener("bbsfox@ettoolong:bbsfox-addonCommand", handleAddonCommand, false);

let init = function() {
if(content) {
let bbscore = content.bbsfox;
if(bbscore) {
//console.log("bbsfox_frame_script: sendSyncMessage frameScriptReady");
sendSyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", {command: "frameScriptReady"});
bbscore.setFrameScript( function(command, async){
if(!async)
return sendSyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", command);
else
return sendAsyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", command);
}.bind(this));
//if(init)
// bbscore.setSelectStatus(message.data.selected); //TODO: still need this ?
bbscore.setFrameScript(frameScript, true);
} else if(bbscore !== null) {
sendSyncMessage("bbsfox@ettoolong:bbsfox-coreCommand", {command:"removeStatus"});
if(content.document.location.protocol === "telnet:" || content.document.location.protocol === "ssh:") {
Expand All @@ -72,19 +93,10 @@ let init = function() {
};

//fire event from bbsfox overlay tabAttrModified
addMessageListener("bbsfox@ettoolong:bbsfox-overlayEvent", function(message) {
if(message.data.command === "update") {
if(content) {
let bbscore = content.bbsfox;
if(bbscore) {
bbscore.updateTabInfo();
}
}
}
});
addMessageListener("bbsfox@ettoolong:bbsfox-overlayEvent", handleOverlayEvent, false);

addEventListener("DOMContentLoaded", function(event) {
//console.log("DOMContentLoaded: " + content.document.location.protocol);
//console.log("DOMContentLoaded: " + content.document.location);
let doc = event.originalTarget;
if(event.originalTarget.nodeName == "#document"){
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
Expand All @@ -93,3 +105,10 @@ addEventListener("DOMContentLoaded", function(event) {
.initWithCallback({ notify: init },10,Ci.nsITimer.TYPE_ONE_SHOT);
}
}, false);

if(content) {
let bbscore = content.bbsfox;
if(bbscore) {
bbscore.setFrameScript(frameScript, false);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "BBSFox",
"name": "bbsfox",
"id": "{86095750-AD15-46d8-BF32-C0789F7E6A32}",
"version": "5.0.11",
"version": "5.0.12",
"description": "Telnet client extension specifically designed for BBS browsing.",
"main": "data/js/addon-script.js",
"author": "[email protected]",
Expand Down

0 comments on commit c4787d0

Please sign in to comment.