Skip to content

Commit

Permalink
Don't inject multiple instances of link hint CSS on repeated invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
JGregoryAtiba committed Jul 27, 2015
1 parent 6b65875 commit 98783d5
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions sVim.safariextension/sVimHint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sVimHint.start = function(newTab) {
var inputKey = "";
var lastMatchHint = null;
var k=0;
var hintClass = "sVimLinkHint";
var hintStyleId = "sVimLinkHintStyle";

function getAbsolutePosition( elem, html, body, inWidth, inHeight ){
var style = getComputedStyle(elem,null);
Expand Down Expand Up @@ -58,10 +60,17 @@ sVimHint.start = function(newTab) {

function injectCSS(doc, css)
{
var style = doc.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
doc.getElementsByTagName('head')[0].appendChild(style);
var style = doc.getElementById(hintStyleId);
if (style) {
style.innerHTML = css;
}
else {
style = doc.createElement('style');
style.type = 'text/css';
style.id = hintStyleId;
style.innerHTML = css;
doc.getElementsByTagName('head')[0].appendChild(style);
}
}

function start(win){
Expand All @@ -88,7 +97,7 @@ sVimHint.start = function(newTab) {
var hint = createText(k);
var span = win.document.createElement("span");
span.appendChild(document.createTextNode(hint));
span.className = "sVimLinkHint";
span.className = hintClass;
var st = span.style;
for( key in spanStyle ){
st[key] = spanStyle[key];
Expand Down

0 comments on commit 98783d5

Please sign in to comment.