Skip to content

Commit

Permalink
updates for TB68
Browse files Browse the repository at this point in the history
TB before 68 are not supported.
- use "manifest.json" instead of "install.rdf"
- added icon svg
- options.xul doesn't use overlayed preference dialog because it is not rendered its layout correctly.
- newmailalert.js was rewritten using es6
  • Loading branch information
kzmi committed Dec 31, 2019
1 parent d9bf3df commit dca389c
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 176 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright(c) 2007-2020 Iwasa Kazmi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4 changes: 0 additions & 4 deletions README

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Blinking Alert
==============

Thunderbird add-on that adds blink feature to the new-mail alert.

[https://addons.thunderbird.net/en-US/thunderbird/addon/blinking-alert/](https://addons.thunderbird.net/en-US/thunderbird/addon/blinking-alert/)

## About this Add-on

The default new-mail alert is subtle if the alert sound was turned off.
This extension adds blink feature to the new-mail alert.
You can also disable auto-hiding of the alert.

After the extension is installed, some options are added to the "Customize New Mail Alert" dialog.
Open "Options" dialog, select "General" page, and click "Customize" button right to the "Show an alert" check box.

If auto-hiding was disabled, you have to click close[X] button of the alert box to close it.
6 changes: 6 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extensionDescription": {
"message": "Adds extra features to the new-mail alert",
"description": "Description of the extension."
}
}
6 changes: 6 additions & 0 deletions src/_locales/ja/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extensionDescription": {
"message": "新着メール通知に付加機能を追加します",
"description": "Description of the extension."
}
}
173 changes: 81 additions & 92 deletions src/chrome/content/messenger/newmailalert.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Blinking Alert
*
* Copyright(c) 2007-2014 Iwasa Kazmi
* Copyright(c) 2007-2020 Iwasa Kazmi
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -22,101 +22,90 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
((window) => {

(function(window) {
const debug = false;

var debug = false;
const consoleService = window.Components.classes["@mozilla.org/consoleservice;1"]
.getService(window.Components.interfaces.nsIConsoleService);

var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
function log(msg) {
if (debug) {
consoleService.logStringMessage("Blinking Alert : " + msg);
}
function log(msg) {
if (debug) {
consoleService.logStringMessage("Blinking Alert : " + msg);
}
}

log("addEventListener");

window.addEventListener("load", () => {
log("onload");

// original handlers
let onAlertLoadOrig = window.onAlertLoad;
let fadeOutAlertOrig = window.fadeOutAlert;
let closeAlertOrig = window.closeAlert;

log("onAlertLoadOrig : " + typeof (onAlertLoadOrig));
log("fadeOutAlertOrig : " + typeof (fadeOutAlertOrig));
log("closeAlertOrig : " + typeof (closeAlertOrig));

// settings
let blinkInterval = 0;
let blinkColor = "#ff6600";
let disableAutoHide = false;
let closeOnClick = false;

// read out our initial settings from prefs.
try {
const prefBranch = window.Components.classes["@mozilla.org/preferences-service;1"]
.getService(window.Components.interfaces.nsIPrefService)
.getBranch(null);
disableAutoHide = prefBranch.getBoolPref("extensions.blinkingAlert.disableAutoHide");
blinkInterval = prefBranch.getIntPref("extensions.blinkingAlert.blinkInterval");
blinkColor = prefBranch.getCharPref("extensions.blinkingAlert.blinkColor");
closeOnClick = prefBranch.getBoolPref("extensions.blinkingAlert.closeOnClick");
} catch (ex) { }

// replace fadeOutAlert()
window.fadeOutAlert = () => {
log("fadeOutAlert called");
if (!disableAutoHide && fadeOutAlertOrig != null) {
log("call original fadeOutAlert");
fadeOutAlertOrig();
fadeOutAlertOrig = null;
}
};

// handle click event
window.addEventListener("click", function () {
log("onclick");
if (closeOnClick && closeAlertOrig != null) {
log("call original closeAlert");
closeAlertOrig();
closeAlertOrig = null;
}
}, false);

log("addEventListener");

window.addEventListener("load", function() {
log("onload");

// original handlers
var onAlertLoadOrig = window.onAlertLoad;
var fadeOutAlertOrig = window.fadeOutAlert;
var closeAlertOrig = window.closeAlert;

log("onAlertLoadOrig : " + typeof(onAlertLoadOrig));
log("fadeOutAlertOrig : " + typeof(fadeOutAlertOrig));
log("closeAlertOrig : " + typeof(closeAlertOrig));

// settings
var blinkInterval = 0;
var blinkColor = "#ff6600";
var disableAutoHide = false;
var closeOnClick = false;

// original background color
var origBackgroundColor = '';
var hasOrigBackgroundColor = false;

// replace fadeOutAlert()
window.fadeOutAlert = function() {
log("fadeOutAlert called");
if (!disableAutoHide && fadeOutAlertOrig != null) {
log("call original fadeOutAlert");
fadeOutAlertOrig();
fadeOutAlertOrig = null;
}
};

// handle click event
window.addEventListener("click", function() {
log("onclick");
if (closeOnClick && closeAlertOrig != null) {
log("call original closeAlert");
closeAlertOrig();
closeAlertOrig = null;
}
}, false);

// blinking function
var blink2 = null;
var blink1 = function() {
log("blink1");
var elem = document.getElementById("alertBox");
if (elem) {
if (!hasOrigBackgroundColor) {
origBackgroundColor = elem.style.backgroundColor;
hasOrigBackgroundColor = true;
}
elem.style.backgroundColor = blinkColor;
setTimeout(blink2, blinkInterval);
}
};

blink2 = function() {
log("blink2");
var elem = document.getElementById("alertBox");
if (elem) {
elem.style.backgroundColor = origBackgroundColor;
setTimeout(blink1, blinkInterval);
}
};

// read out our initial settings from prefs.
try {
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null);
disableAutoHide = prefBranch.getBoolPref("extensions.blinkingAlert.disableAutoHide");
blinkInterval = prefBranch.getIntPref ("extensions.blinkingAlert.blinkInterval");
blinkColor = prefBranch.getCharPref("extensions.blinkingAlert.blinkColor");
closeOnClick = prefBranch.getBoolPref("extensions.blinkingAlert.closeOnClick");
} catch (ex) {}

// set time to start blinking
if (blinkInterval > 0) {
log("start blinking");
setTimeout(blink1, 0);
// blinking function
const blink = (origBgColor) => {
log("blink");
const elem = window.document.getElementById("alertBox");
if (elem) {
if (origBgColor !== null) {
elem.style.backgroundColor = origBgColor;
origBgColor = null;
} else {
origBgColor = elem.style.backgroundColor;
elem.style.backgroundColor = blinkColor;
}
}, false);
window.setTimeout(() => blink(origBgColor), blinkInterval);
}
};

// start blinking
if (blinkInterval > 0) {
log("start blinking");
window.setTimeout(() => blink(null), 0);
}
}, false);
})(window);

5 changes: 2 additions & 3 deletions src/chrome/content/messenger/newmailalert.xul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* Blinking Alert
*
* Copyright(c) 2007-2014 Iwasa Kazmi
* Copyright(c) 2007-2020 Iwasa Kazmi
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -27,6 +27,5 @@
-->
<overlay id="BlinkingMailAlertNotification"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://blinkingalert/content/messenger/newmailalert.js"/>
<script src="chrome://blinkingalert/content/messenger/newmailalert.js"/>
</overlay>

41 changes: 24 additions & 17 deletions src/chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* Blinking Alert
*
* Copyright(c) 2007-2014 Iwasa Kazmi
* Copyright(c) 2007-2020 Iwasa Kazmi
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -25,21 +25,28 @@
* THE SOFTWARE.
*/
-->
<?xul-overlay href="chrome://messenger/content/preferences/notifications.xul"?>
<!-- *******************************
The prefwindow in notifications.xul is a "child" dialog.
We need a top-level prefwindow as an option dialog.
*********************************-->
<?xml-stylesheet href="chrome://global/skin/"?>
<?xml-stylesheet href="chrome://messenger/skin/preferences/preferences.css"?>
<?xml-stylesheet href="chrome://mozapps/content/preferences/preferences.css"?>
<!DOCTYPE prefwindow [
<!ENTITY % notificationsDTD SYSTEM "chrome://messenger/locale/preferences/notifications.dtd">
%notificationsDTD;
]>
<prefwindow id="StickAlertOptionsDialog"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
dlgbuttons="accept,cancel"
title="&notificationsDialog2.title;">
<prefpane id="NotificationsDialogPane"/>
</prefwindow>
<!DOCTYPE dialog SYSTEM "chrome://blinkingalert/locale/notifications.dtd">
<dialog id="BlinkingAlertOptionsDialog"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml"
type="child"
buttons="accept,cancel"
title="&prefDialog.title;">
<vbox>
<checkbox id="disableAutoHide" class="indent" label="&disableAutoHide.label;" preference="extensions.blinkingAlert.disableAutoHide"/>
<checkbox id="closeOnClick" class="indent" label="&closeOnClick.label;" preference="extensions.blinkingAlert.closeOnClick"/>
<hbox class="indent" align="center">
<label id="blinkIntervalLabel" value="&blinkInterval.label;" control="blinkInterval"/>
<html:input id="blinkInterval" type="number" min="0" preference="extensions.blinkingAlert.blinkInterval" style="width:5em;"/>
<label id="blinkIntervalUnit" value="&blinkIntervalUnit.label; (0:&noBlink.label;)" control="blinkInterval"/>
</hbox>
<hbox class="indent" align="center">
<label id="blinkColorLabel" value="&blinkColor.label;" control="blinkColor"/>
<html:input type="color" id="blinkColor" preference="extensions.blinkingAlert.blinkColor"/>
</hbox>
</vbox>
<script src="chrome://global/content/preferencesBindings.js"/>
<script src="chrome://blinkingalert/content/preferences/notifications.js"/>
</dialog>
30 changes: 30 additions & 0 deletions src/chrome/content/preferences/notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Blinking Alert
*
* Copyright(c) 2007-2020 Iwasa Kazmi
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
Preferences.addAll([
{ id: "extensions.blinkingAlert.disableAutoHide", type: "bool" },
{ id: "extensions.blinkingAlert.blinkInterval", type: "int" },
{ id: "extensions.blinkingAlert.blinkColor", type: "string" },
{ id: "extensions.blinkingAlert.closeOnClick", type: "bool" },
]);
Loading

0 comments on commit dca389c

Please sign in to comment.