Verified Commit 1e823097 authored by Andrew Sachen's avatar Andrew Sachen 🖱
Browse files

Initial Commit

parents
custom: https://realityripple.com/donate.php?itm=Pang
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
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 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.
For more information, please refer to <http://unlicense.org/>
# Pang
Display the response time (ping) of the current webpage.
#### Supports
* Pale Moon [25.0a1pre - 29.*]
## Building
Simply download the contents of the repository and pack the contents (sans git data) into a .zip file. Then, rename the file to .xpi and drag into the browser.
## Download
You can grab the latest release from the [Official Web Site](//realityripple.com/Software/Mozilla-Extensions/Pang/).
content pang chrome/content/
locale pang en-US chrome/locale/en-US/
skin pang skin chrome/skin/
overlay chrome://browser/content/browser.xul chrome://pang/content/overlay.xul
style chrome://global/content/customizeToolbar.xul chrome://pang/skin/overlay.css
var Pang =
{
cache: null,
medium: 300,
high: 600,
timeout: 6000,
interval: 30000,
tmr: null,
init: function()
{
Pang.cache = new Map();
let progressListener =
{
onLocationChange : Pang.onLocationChange,
onProgressChange : function() {},
onSecurityChange : function() {},
onStateChange : function() {},
onStatusChange : function() {}
};
window.getBrowser().addProgressListener(progressListener);
},
onLocationChange: function()
{
let prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
if (prefs.prefHasUserValue('extensions.pang.increment'))
Pang.interval = (prefs.getIntPref('extensions.pang.increment') * 1000);
else
Pang.interval = 30000;
if (prefs.prefHasUserValue('extensions.pang.timeout'))
Pang.timeout = (prefs.getIntPref('extensions.pang.timeout') * 1000);
else
Pang.timeout = 6000;
if (prefs.prefHasUserValue('extensions.pang.high'))
Pang.high = prefs.getIntPref('extensions.pang.high');
else
Pang.high = 600;
if (prefs.prefHasUserValue('extensions.pang.medium'))
Pang.medium = prefs.getIntPref('extensions.pang.medium');
else
Pang.medium = 300;
if (Pang.tmr !== null)
{
window.clearTimeout(Pang.tmr);
Pang.tmr = null;
}
if (document.getElementById('pang-tb') === null)
return;
let currentURI = window.getBrowser().selectedBrowser.currentURI;
if (currentURI.spec.startsWith('about:reader?url='))
{
Pang.showNull();
return;
}
if (currentURI.scheme === 'view-source')
{
Pang.showNull();
return;
}
if (currentURI.scheme === 'jar')
{
Pang.showNull();
return;
}
if (currentURI.scheme === 'chrome')
{
Pang.showNull();
return;
}
if (currentURI.scheme === 'about')
{
Pang.showNull();
return;
}
let sPath = currentURI.prePath + '/.well-known/time';
let cached = Pang.cache.get(sPath);
var start = new Date().getTime();
if (cached)
{
let stored = cached[0];
if (stored === -1)
Pang.showTimeout();
else
Pang.showResult(stored);
let updated = cached[1];
if (updated < start)
{
let diff = Pang.interval;
if (diff > 0)
{
if ((start - updated) < diff)
{
diff -= (start - updated);
Pang.tmr = window.setTimeout(Pang.onLocationChange, diff);
return;
}
}
}
}
else
{
document.getElementById('pang-tb').className = 'null';
if (document.getElementById('pang-tb').hasAttribute('tooltiptext'))
document.getElementById('pang-tb').removeAttribute('tooltiptext');
}
let ping = new XMLHttpRequest();
ping.onreadystatechange = function()
{
if (ping.readyState !== 4)
return;
let end = new Date().getTime();
Pang.cache.delete(sPath);
Pang.cache.set(sPath, [(end - start), end]);
Pang.showResult(end - start);
if (Pang.interval > 0)
Pang.tmr = window.setTimeout(Pang.onLocationChange, Pang.interval);
};
ping.ontimeout = function()
{
let end = new Date().getTime();
Pang.cache.delete(sPath);
Pang.cache.set(sPath, [-1, end]);
Pang.showTimeout();
if (Pang.interval > 0)
Pang.tmr = window.setTimeout(Pang.onLocationChange, Pang.interval);
};
ping.onerror = function()
{
let end = new Date().getTime();
Pang.cache.delete(sPath);
Pang.cache.set(sPath, [-1, end]);
Pang.showTimeout();
if (Pang.interval > 0)
Pang.tmr = window.setTimeout(Pang.onLocationChange, Pang.interval);
};
ping.timeout = Pang.timeout;
ping.open('GET', sPath, true);
ping.send();
},
showNull: function()
{
if (document.getElementById('pang-tb') === null)
return;
document.getElementById('pang-tb').className = 'null';
if (document.getElementById('pang-tb').hasAttribute('tooltiptext'))
document.getElementById('pang-tb').removeAttribute('tooltiptext');
},
showResult: function(t)
{
if (document.getElementById('pang-tb') === null)
return;
let color = 'green';
if (t > Pang.high)
color = 'red';
else if (t > Pang.medium)
color = 'yellow';
document.getElementById('pang-tb').className = color;
let ttTime = Components.classes['@mozilla.org/intl/stringbundle;1'].getService(Components.interfaces.nsIStringBundleService).createBundle('chrome://pang/locale/pang.properties').GetStringFromName('ping.time');
ttTime = ttTime.replace('%1', t);
document.getElementById('pang-tb').setAttribute('tooltiptext', ttTime);
},
showTimeout: function()
{
if (document.getElementById('pang-tb') === null)
return;
document.getElementById('pang-tb').className = 'timeout';
let ttTimeout = Components.classes['@mozilla.org/intl/stringbundle;1'].getService(Components.interfaces.nsIStringBundleService).createBundle('chrome://pang/locale/pang.properties').GetStringFromName('ping.timeout');
document.getElementById('pang-tb').setAttribute('tooltiptext', ttTimeout);
}
};
window.addEventListener('load', Pang.init, false);
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://pang/skin/overlay.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://pang/locale/pang.dtd">
<overlay id="timerfoxOverlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://pang/content/overlay.js"/>
<toolbarpalette id="BrowserToolbarPalette">
<toolbaritem id="pang-tb"/>
</toolbarpalette>
<toolbaritem id="pang-tb" removable="true" align="center" pack="center">
<image/>
</toolbaritem>
</overlay>
<?xml version="1.0"?>
<!DOCTYPE prefs SYSTEM "chrome://pang/locale/prefs.dtd">
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting type="integer" pref="extensions.pang.increment" title="&pang.increment.title;" desc="&pang.increment.desc;" min="0" max="180" />
<setting type="integer" pref="extensions.pang.timeout" title="&pang.timeout.title;" desc="&pang.timeout.desc;" min="5" max="60" />
<setting type="integer" pref="extensions.pang.medium" title="&pang.medium.title;" desc="&pang.medium.desc;" min="50" max="500" />
<setting type="integer" pref="extensions.pang.high" title="&pang.high.title;" desc="&pang.high.desc;" min="500" max="60000" />
</vbox>
extensions.{3B1A6514-0F92-572E-AE65-3BFBB55C4D68}.description=Display the response time (ping) of the current webpage.
ping.time=%1 ms
ping.timeout=No Response
<!ENTITY pang.increment.title "Interval:">
<!ENTITY pang.increment.desc "Seconds to wait before updating the ping (0 = ping once).">
<!ENTITY pang.timeout.title "Timeout:">
<!ENTITY pang.timeout.desc "Seconds to wait before giving up on ping response.">
<!ENTITY pang.medium.title "Medium Ping:">
<!ENTITY pang.medium.desc "Minimum medium latency value.">
<!ENTITY pang.high.title "High Ping:">
<!ENTITY pang.high.desc "Minimum high latency value.">
#pang-tb
{
width: 11px;
height: 24px;
margin: 0 3px;
list-style-image: url(chrome://pang/skin/large/green.png);
}
#pang-tb.null
{
list-style-image: url(chrome://pang/skin/large/null.png);
}
#pang-tb.red
{
list-style-image: url(chrome://pang/skin/large/red.png);
}
#pang-tb.yellow
{
list-style-image: url(chrome://pang/skin/large/yellow.png);
}
#pang-tb.green
{
list-style-image: url(chrome://pang/skin/large/green.png);
}
#pang-tb.timeout
{
list-style-image: url(chrome://pang/skin/large/timeout.png);
}
toolbar[iconsize="small"] #pang-tb
{
width: 7px;
height: 16px;
list-style-image: url(chrome://pang/skin/small/green.png);
}
toolbar[iconsize="small"] #pang-tb.null
{
list-style-image: url(chrome://pang/skin/small/null.png);
}
toolbar[iconsize="small"] #pang-tb.red
{
list-style-image: url(chrome://pang/skin/small/red.png);
}
toolbar[iconsize="small"] #pang-tb.yellow
{
list-style-image: url(chrome://pang/skin/small/yellow.png);
}
toolbar[iconsize="small"] #pang-tb.green
{
list-style-image: url(chrome://pang/skin/small/green.png);
}
toolbar[iconsize="small"] #pang-tb.timeout
{
list-style-image: url(chrome://pang/skin/small/timeout.png);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment