Use id to avoid inserting adblock/ form history style more than once

This commit is contained in:
Alexander Butenko 2009-12-23 15:35:09 +01:00 committed by Christian Dywan
parent 973e4aa907
commit 05601be635
2 changed files with 6 additions and 6 deletions

View file

@ -44,11 +44,8 @@ adblock_build_js (const gchar* style,
return g_strdup_printf (
"window.addEventListener ('DOMContentLoaded',"
"function () {"
" var styles = document.getElementsByTagName('style');"
" for (i=0; i<styles.length; i++) {"
" if (styles[i].getAttribute('title') == 'madblock')"
" return;"
" }"
" if (document.getElementById('madblock'))"
" return;"
" var URL = location.href;"
" var sites = new Array(); %s;"
" var public = '%s';"
@ -60,7 +57,7 @@ adblock_build_js (const gchar* style,
" public += ' {display: none !important;}';"
" var mystyle = document.createElement('style');"
" mystyle.setAttribute('type', 'text/css');"
" mystyle.setAttribute('title', 'madblock');"
" mystyle.setAttribute('id', 'madblock');"
" mystyle.appendChild(document.createTextNode(public));"
" var head = document.getElementsByTagName('head')[0];"
" if (head) head.appendChild(mystyle);"

View file

@ -58,9 +58,12 @@ formhistory_prepare_js ()
"%s"
"window.addEventListener ('DOMContentLoaded',"
"function () {"
" if (document.getElementById('formhistory'))"
" return;"
" initSuggestions ();"
" var mystyle = document.createElement('style');"
" mystyle.setAttribute('type', 'text/css');"
" mystyle.setAttribute('id', 'formhistory');"
" mystyle.appendChild(document.createTextNode('%s'));"
" var head = document.getElementsByTagName('head')[0];"
" if (head) head.appendChild(mystyle);"