From 2fac8bb5b57064e793a2db6effc5e13921bfc21b Mon Sep 17 00:00:00 2001 From: Elbert Alias Date: Sun, 25 Nov 2012 10:37:20 +1100 Subject: [PATCH] Removed jQuery dependency from Chrome driver --- drivers/chrome/js/i18n.js | 16 +++++++++++---- drivers/chrome/js/options.js | 33 +++++++++++++++++------------- drivers/chrome/js/popup.js | 39 +++++++++++++++++++++--------------- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/drivers/chrome/js/i18n.js b/drivers/chrome/js/i18n.js index 1548b0cdf..f8207e6e1 100644 --- a/drivers/chrome/js/i18n.js +++ b/drivers/chrome/js/i18n.js @@ -1,5 +1,13 @@ -$(function() { - $('[data-i18n]').each(function() { - $(this).html(chrome.i18n.getMessage($(this).attr('data-i18n'))); - }); +document.addEventListener('DOMContentLoaded', function() { + var + i, value, + d = document + nodes = d.getElementsByTagName('*') + ; + + for ( i = 0; i < nodes.length; i ++ ) { + if ( attr = nodes[i].dataset.i18n ) { + nodes[i].innerHTML = chrome.i18n.getMessage(attr); + } + } }); diff --git a/drivers/chrome/js/options.js b/drivers/chrome/js/options.js index 8a4d67c31..36164c60b 100644 --- a/drivers/chrome/js/options.js +++ b/drivers/chrome/js/options.js @@ -1,15 +1,17 @@ -$(function() { +document.addEventListener('DOMContentLoaded', function() { + var d = document; + var options = { opts: defaults, init: function() { options.load(); - $('#github' ).click(function() { window.open(wappalyzer.config.githubURL); }); - $('#twitter' ).click(function() { window.open(wappalyzer.config.twitterURL); }); - $('#wappalyzer').click(function() { window.open(wappalyzer.config.websiteURL + '?utm_source=chrome&utm_medium=extension&utm_campaign=extensions'); }); + d.getElementById('github' ).addEventListener('click', function() { window.open(wappalyzer.config.githubURL); }); + d.getElementById('twitter' ).addEventListener('click', function() { window.open(wappalyzer.config.twitterURL); }); + d.getElementById('wappalyzer').addEventListener('click', function() { window.open(wappalyzer.config.websiteURL + '?utm_source=chrome&utm_medium=extension&utm_campaign=extensions'); }); - $('#options-save').click(options.save); + d.getElementById('options-save').addEventListener('click', options.save); }, load: function() { @@ -20,31 +22,34 @@ $(function() { } if ( parseInt(options.opts.autoAnalyzeHeaders) ) { - $('#option-auto-analyze-headers').attr('checked', 'checked'); + d.getElementById('option-auto-analyze-headers').setAttribute('checked', 'checked'); } if ( parseInt(options.opts.upgradeMessage) ) { - $('#option-upgrade-message').attr('checked', 'checked'); + d.getElementById('option-upgrade-message').setAttribute('checked', 'checked'); } if ( parseInt(options.opts.tracking) ) { - $('#option-tracking').attr('checked', 'checked'); + d.getElementById('option-tracking').setAttribute('checked', 'checked'); } }, save: function() { - options.opts.autoAnalyzeHeaders = $('#option-auto-analyze-headers').is(':checked') ? 1 : 0; - options.opts.upgradeMessage = $('#option-upgrade-message' ).is(':checked') ? 1 : 0; - options.opts.tracking = $('#option-tracking' ).is(':checked') ? 1 : 0; + options.opts.autoAnalyzeHeaders = d.getElementById('option-auto-analyze-headers').checked ? 1 : 0; + options.opts.upgradeMessage = d.getElementById('option-upgrade-message' ).checked ? 1 : 0; + options.opts.tracking = d.getElementById('option-tracking' ).checked ? 1 : 0; for ( option in options.opts ) { localStorage[option] = options.opts[option]; } - document.getElementById('options-saved').style.display = 'inline'; - setTimeout(function(){document.getElementById('options-saved').style.display = 'none';},2000); + d.getElementById('options-saved').style.display = 'inline'; + + setTimeout(function(){ + d.getElementById('options-saved').style.display = 'none'; + }, 2000); } }; options.init(); -}); \ No newline at end of file +}); diff --git a/drivers/chrome/js/popup.js b/drivers/chrome/js/popup.js index e9972ee09..9f83e6cb0 100644 --- a/drivers/chrome/js/popup.js +++ b/drivers/chrome/js/popup.js @@ -1,20 +1,27 @@ -(function() { +document.addEventListener('DOMContentLoaded', function() { + var + d = document, + analyzeHeaders = d.getElementById('analyze-headers'), + detectedApps = d.getElementById('detected-apps') + ; + var popup = { pollHeaders: null, init: function() { - $('#options').click(function() { - window.open(chrome.extension.getURL('options.html')); + d.getElementById('options').addEventListener('click', function() { + open(chrome.extension.getURL('options.html')); }); - $('#analyze-headers').text(chrome.i18n.getMessage('analyzeHeaders')).removeAttr('disabled'); + analyzeHeaders.innerHTML = chrome.i18n.getMessage('analyzeHeaders'); + analyzeHeaders.removeAttribute('disabled'); chrome.tabs.getSelected(null, function(tab) { if ( tab.url.match(/https?:\/\//) ) { - $('#detected-apps').html('
' + chrome.i18n.getMessage('noAppsDetected') + '
'); + detectedApps.innerHTML = '
' + chrome.i18n.getMessage('noAppsDetected') + '
'; - $('#analyze-headers').click(function() { - $(this).attr('disabled', 'disabled'); + analyzeHeaders.addEventListener('click', function() { + analyzeHeaders.setAttribute('disabled', 'disabled'); chrome.extension.sendRequest({ id: 'fetch_headers', tab: tab }); @@ -22,12 +29,12 @@ }); if ( parseInt(localStorage['autoAnalyzeHeaders']) ) { - $('#analyze-headers').click(); + analyzeHeaders.click(); } } else { - $('#detected-apps').html('
' + chrome.i18n.getMessage('nothingToDo') + '
'); + detectedApps.innerHTML = '
' + chrome.i18n.getMessage('nothingToDo') + '
'; - $('#analyze-headers').attr('disabled', 'disabled'); + analyzeHeaders.setAttribute('disabled', 'disabled'); } }); @@ -41,12 +48,12 @@ if ( popup.pollHeaders != null ) { clearTimeout(popup.pollHeaders); - $('#analyze-headers').text(chrome.i18n.getMessage('analyzeHeadersDone')); + analyzeHeaders.innerHTML = chrome.i18n.getMessage('analyzeHeadersDone'); } } if ( response.tabCache.count > 0 ) { - $('#detected-apps').html(''); + detectedApps.innerHTML = ''; response.tabCache.appsDetected.map(function(appName) { html = @@ -67,13 +74,13 @@ '' + ''; - $('#detected-apps').append(html); + detectedApps.innerHTML = detectedApps.innerHTML + html; }); } }); }); } - } + }; - $(function() { popup.init(); }); -})(); + popup.init(); +});