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

Updates #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
Prev Previous commit
Next Next commit
Whitespace and lint fixes
amadeus committed Dec 1, 2011
commit 8ae1eb439da18e54aae21cef2e4d3e0e6030170a
279 changes: 139 additions & 140 deletions globalpage.html
Original file line number Diff line number Diff line change
@@ -1,154 +1,153 @@
<!DOCTYPE HTML>
<html>
<head>
<title>global page</title>
<script type="text/javascript">
var disabledSites = safari.extension.settings.disabledsites;

/* var tabActive = [];
var updating = false;

setInterval("update()", 100);
function update() {
if (!updating && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)] != undefined && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0] != undefined && parseInt(tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0]) != parseInt(safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ))) {
updateing = true;
changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("reset",true);
updating = false;
}
}
<title>Global Page</title>
<script type="text/javascript">

var disabledSites = safari.extension.settings.disabledsites;
/*
var tabActive = [];
var updating = false;

setInterval("update()", 100);

function update() {
if (!updating && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)] != undefined && tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0] != undefined && parseInt(tabActive[safari.application.browserWindows.indexOf(safari.application.activeBrowserWindow)][0]) != parseInt(safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab ))) {
updateing = true;
changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("reset",true);
updating = false;
}
}
*/

String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function disabledSitesHandler() {
if (disabledSites != undefined) {
disabledSitesArray = disabledSites.split(",");

for (var i=0; i < disabledSitesArray.length; i++) {
var ds = disabledSitesArray[i].trim();
currentSite = safari.application.activeBrowserWindow.activeTab.url;
dsm = ds.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
csm = currentSite.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
if (dsm != null && csm != null && dsm[0] == csm[0]) {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("disable",true);
return;
}
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
} else {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
}
}

function disabledSitesChanged(event) {
if (event.key == "disabledsites") {
disabledSites=event.newValue;
disabledSitesHandler();
}
}

safari.extension.settings.addEventListener("change", disabledSitesChanged, false);

function closeTab() {
safari.application.activeBrowserWindow.activeTab.close();
String.prototype.trim = function () {
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function disabledSitesHandler() {
if (disabledSites != undefined) {
disabledSitesArray = disabledSites.split(",");

for (var i=0; i < disabledSitesArray.length; i++) {
var ds = disabledSitesArray[i].trim();
currentSite = safari.application.activeBrowserWindow.activeTab.url;
dsm = ds.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
csm = currentSite.match(/([^\/.]+\.[^\/.]+(?=$|\/))/);
if (dsm != null && csm != null && dsm[0] == csm[0]) {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("disable",true);
return;
}
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
} else {
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("load",true);
}
}

function closeWindow() {
safari.application.activeBrowserWindow.close();
}

function openTab(event) {
var url = event.message;
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (url != "") {
safari.application.activeBrowserWindow.openTab('foreground', ++index).url = url;
} else {
safari.application.activeBrowserWindow.openTab('foreground', ++index);
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
function disabledSitesChanged(event) {
if (event.key == "disabledsites") {
disabledSites=event.newValue;
disabledSitesHandler();
}
}

safari.extension.settings.addEventListener("change", disabledSitesChanged, false);

/* function changeTabActive() {
console.log(safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow ));
if (tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )] != undefined && tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] != undefined) {
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][0] = tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1];
}
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
}
function closeTab() {
safari.application.activeBrowserWindow.activeTab.close();
}

function closeWindow() {
safari.application.activeBrowserWindow.close();
}

function openTab(event) {
var url = event.message;
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (url != "") {
safari.application.activeBrowserWindow.openTab('foreground', ++index).url = url;
} else {
safari.application.activeBrowserWindow.openTab('foreground', ++index);
}
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
}

/*
function changeTabActive() {
console.log(safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow ));
if (tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )] != undefined && tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] != undefined) {
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][0] = tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1];
}
tabActive[safari.application.browserWindows.indexOf( safari.application.activeBrowserWindow )][1] = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
}
*/

function respondToMessage(theMessageEvent) {
switch (theMessageEvent.name) {
case "closeTab":
closeTab();
break;

case "closeWindow":
closeWindow();
break;

case "openTab":
case "newTab":
openTab(theMessageEvent);
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "prevTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (index == 0) {
index = safari.application.activeBrowserWindow.tabs.length-1;
} else {
index--;
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "nextTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (parseInt(theMessageEvent.message, 10) != 0) {
if (theMessageEvent.message == "last") {
index = parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1;
} else if (parseInt(theMessageEvent.message) < safari.application.activeBrowserWindow.tabs.length, 10) {
index = parseInt(theMessageEvent.message, 10)-1;
}
} else {
if (index == parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1) {
index = 0;
} else {
index++;
}
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "backTab":
if (tabActive[0] != undefined && safari.application.activeBrowserWindow.tabs[tabActive[0]]) {
safari.application.activeBrowserWindow.tabs[tabActive[0]].activate();
changeTabActive();
}
break;

case "disabledSites":
disabledSitesHandler();
break;
}
function respondToMessage(theMessageEvent) {
switch (theMessageEvent.name) {
case "closeTab":
closeTab();
break;

case "closeWindow":
closeWindow();
break;

case "openTab":
case "newTab":
openTab(theMessageEvent);
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "prevTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (index == 0) {
index = safari.application.activeBrowserWindow.tabs.length-1;
} else {
index--;
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "nextTab":
var index = safari.application.activeBrowserWindow.tabs.indexOf( safari.application.activeBrowserWindow.activeTab );
if (parseInt(theMessageEvent.message, 10) != 0) {
if (theMessageEvent.message == "last") {
index = parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1;
} else if (parseInt(theMessageEvent.message) < safari.application.activeBrowserWindow.tabs.length, 10) {
index = parseInt(theMessageEvent.message, 10)-1;
}
} else {
if (index == parseInt(safari.application.activeBrowserWindow.tabs.length, 10)-1) {
index = 0;
} else {
index++;
}
}
safari.application.activeBrowserWindow.tabs[index].activate();
// changeTabActive();
safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("resetcombo", true);
break;

case "backTab":
if (tabActive[0] != undefined && safari.application.activeBrowserWindow.tabs[tabActive[0]]) {
safari.application.activeBrowserWindow.tabs[tabActive[0]].activate();
changeTabActive();
}
break;

case "disabledSites":
disabledSitesHandler();
break;
}

safari.application.addEventListener("message",respondToMessage,false);

</script>
</head>
<body> </body>
</html>
}

safari.application.addEventListener("message",respondToMessage,false);

</script>
</head>
<body></body>
</html>
6 changes: 2 additions & 4 deletions overlay.js
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ if (window.top === window) {
overlay.style.display = "none";
overlay.setAttribute('id', 'vimOverlay');
overlay.style.opacity = ".9";
overlay.style.zIndex = "2147483648";
overlay.style.zIndex = "2147483648";

var overlayTextinput = document.createElement("input");
overlayTextinput.style.border = "0";
@@ -25,11 +25,9 @@ if (window.top === window) {
overlayTextinput.style.color = "black";
overlayTextinput.style.margin = "0";
overlayTextinput.style.opacity = ".9";
overlayTextinput.style.clear = "none";
overlayTextinput.style.clear = "none";
overlayTextinput.setAttribute('id', 'vimOverlayTextinput');

document.body.insertBefore(overlay, document.body.firstChild);
overlay.appendChild(overlayTextinput);


}
Loading