From 915c0f3ee115d504ad38fd0d1e95c8cd10a7b931 Mon Sep 17 00:00:00 2001 From: Sidharth Kapur Date: Tue, 1 Jul 2014 14:36:19 -0500 Subject: [PATCH] Finalized info display with popup settings. Updated version to 1.1 --- src/background.js | 30 +++++++ src/cis/contentScript.js | 18 +--- src/manifest.json | 14 ++- src/options.html | 24 ++++- src/options.js | 40 +++------ src/registrar/contentScript.js | 153 +++++++++++++++++++++++++------- src/registrar/registrar.css | 31 +++++++ src/resources/information35.png | Bin 0 -> 1926 bytes 8 files changed, 231 insertions(+), 79 deletions(-) create mode 100644 src/background.js create mode 100644 src/registrar/registrar.css create mode 100644 src/resources/information35.png diff --git a/src/background.js b/src/background.js new file mode 100644 index 0000000..b4d685c --- /dev/null +++ b/src/background.js @@ -0,0 +1,30 @@ + +// Check whether new version is installed +chrome.runtime.onInstalled.addListener(function(details) { + var settings = ['concatRegistrarResults', 'showRegistrarInfoIcons', 'makeCisCharts']; + + chrome.storage.sync.get(settings, function(items) { + var setting; + + for (var i in settings) { + setting = settings[i]; + if (!items.hasOwnProperty(setting)) { + // Enable all settings that haven't been explicitly enabled or disabled before. + chrome.storage.sync.set({setting: true}, function() { }); + } + } + }); + + chrome.tabs.create({ + url: chrome.extension.getURL('options.html') + }); + + // Stackoverflow copypasta: + + // if(details.reason == "install"){ + // console.log("This is a first install!"); + // } else if(details.reason == "update"){ + // var thisVersion = chrome.runtime.getManifest().version; + // console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!"); + // } +}); \ No newline at end of file diff --git a/src/cis/contentScript.js b/src/cis/contentScript.js index a1b728c..156d709 100644 --- a/src/cis/contentScript.js +++ b/src/cis/contentScript.js @@ -3,22 +3,10 @@ var $ = jQuery; $(function() { - chrome.storage.sync.get('runScriptOnCisPage', function(items) { - var justEnabledSetting = false; + chrome.storage.sync.get('makeCisCharts', function(items) { - if (!items.hasOwnProperty('runScriptOnCisPage')) { - // First time using the extension - // Let's enable it by default. - chrome.storage.sync.set({'runScriptOnCisPage': true}, function() { - console.log('Run script on Registrar Page enabled by default.'); - }); - - justEnabledSetting = true; - } - - // Run the script only if the user has checked the box in the extension options, - // or if the script has been enabled by default the first time this page was opened. - if (items.runScriptOnCisPage || justEnabledSetting) { + // Run the script only if the user has checked the box in the extension options + if (items.makeCisCharts) { makeCharts(); } }); diff --git a/src/manifest.json b/src/manifest.json index d37233a..96e75ff 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -3,7 +3,7 @@ "name": "UT Course Registration", "description": "Adds features to UT's course catalog.", - "version": "1.0", + "version": "1.1", "permissions": [ "https://utdirect.utexas.edu/registrar/", @@ -13,7 +13,8 @@ "content_scripts": [ { "matches": ["https://utdirect.utexas.edu/registrar/nrclav/results.WBX*"], - "js": ["jquery-2.1.1.min.js", "registrar/contentScript.js", "common.js"] + "js": ["jquery-2.1.1.min.js", "registrar/contentScript.js", "common.js"], + "css": ["registrar/registrar.css"] }, { "matches": ["https://utdirect.utexas.edu/ctl/ecis/results/view_results.WBX*"], @@ -22,5 +23,14 @@ } ], + "web_accessible_resources":[ + "resources/*" + ], + + "background": { + "scripts": ["background.js"], + "persistent": false + }, + "options_page": "options.html" } \ No newline at end of file diff --git a/src/options.html b/src/options.html index 14d03d9..a47cb14 100644 --- a/src/options.html +++ b/src/options.html @@ -4,16 +4,34 @@ Options - UT Course Registration Extension - +

Options - UT Course Registration Extension

- Concatenate pages on registrar site + + + Concatenate pages on registrar site + + +
- Draw bar charts on Course Instructor Survey site + + + + Make info icons for class details on registrar site + + + +
+ + + + Draw bar charts on Course Instructor Survey site + +
\ No newline at end of file diff --git a/src/options.js b/src/options.js index eff247f..d3f0e49 100644 --- a/src/options.js +++ b/src/options.js @@ -1,40 +1,28 @@ document.addEventListener('DOMContentLoaded', function() { - chrome.storage.sync.get(['runScriptOnRegistrarPage', 'runScriptOnCisPage'], function(items) { + chrome.storage.sync.get(['concatRegistrarResults', 'showRegistrarInfoIcons', 'makeCisCharts'], function(items) { - if (items.hasOwnProperty('runScriptOnRegistrarPage')) { - document.getElementById('registrarCheckbox').checked = items['runScriptOnRegistrarPage']; - } else { - // On first run of application, turn features on by default. - document.getElementById('registrarCheckbox').checked = true; - } + document.getElementById('concatCheckbox').checked = items['concatRegistrarResults']; + document.getElementById('infoIconsCheckbox').checked = items['showRegistrarInfoIcons']; + document.getElementById('cisCheckbox').checked = items['makeCisCharts']; - if (items.hasOwnProperty('runScriptOnCisPage')) { - document.getElementById('cisCheckbox').checked = items['runScriptOnCisPage']; - } else { - // On first run of application, turn features on by default. - document.getElementById('cisCheckbox').checked = true; - } - - // We may have just checked the checkboxes by default on the first run. - // Update preferences here just to make sure that this change is saved. - updatePrefs(); }); - document.getElementById('registrarCheckbox').addEventListener('change', updatePrefs); + document.getElementById('concatCheckbox').addEventListener('change', updatePrefs); + document.getElementById('infoIconsCheckbox').addEventListener('change', updatePrefs); document.getElementById('cisCheckbox').addEventListener('change', updatePrefs); }); function updatePrefs() { - var isRegistrarOptionChecked, isCisOptionChecked, settings; + var isConcatOptionChecked = document.getElementById('concatCheckbox').checked, + isInfoIconsOptionChecked = document.getElementById('infoIconsCheckbox').checked, + isCisChartsOptionChecked = document.getElementById('cisCheckbox').checked, + settings = { + 'concatRegistrarResults': isConcatOptionChecked, + 'showRegistrarInfoIcons': isInfoIconsOptionChecked, + 'makeCisCharts': isCisChartsOptionChecked + }; - isRegistrarOptionChecked = document.getElementById('registrarCheckbox').checked; - isCisOptionChecked = document.getElementById('cisCheckbox').checked; - - settings = { - 'runScriptOnRegistrarPage': isRegistrarOptionChecked, - 'runScriptOnCisPage': isCisOptionChecked - }; chrome.storage.sync.set(settings, function() { console.log('settings updated'); }); diff --git a/src/registrar/contentScript.js b/src/registrar/contentScript.js index 3022ecc..9f8e7f1 100644 --- a/src/registrar/contentScript.js +++ b/src/registrar/contentScript.js @@ -1,52 +1,137 @@ var $ = jQuery; +var concatRegistrarResults; +var doMakeInfoIcons; $(function() { - chrome.storage.sync.get('runScriptOnRegistrarPage', function(items) { - var $body; - var justEnabledSetting = false; + chrome.storage.sync.get(['concatRegistrarResults', 'showRegistrarInfoIcons'], function(items) { - if (!items.hasOwnProperty('runScriptOnRegistrarPage')) { - // First time using the extension - // Let's enable it by default. - chrome.storage.sync.set({'runScriptOnRegistrarPage': true}, function() { - console.log('Run script on Registrar Page enabled by default.'); - }); + concatRegistrarResults = items.concatRegistrarResults; + doMakeInfoIcons = items.showRegistrarInfoIcons; - justEnabledSetting = true; - } - - // Run the script only if the user has checked the box in the extension options, - // or if the script has been enabled by default the first time this page was opened. - if (items.runScriptOnRegistrarPage || justEnabledSetting) { - - $body = $('body'); + // Run the script only if the user has checked the box in the extension options + if (items.concatRegistrarResults) { - $body.append($('')) - loadMorePages($body); + // Use setTimeout() instead of explicitly calling run() because + // errors are formatted weirdly when errors + // happen inside of a chrome.storage.sync.get() callback - injectFontAwesome(); + // Concat the pages, and if user wants info icons to be made, make user icons. + setTimeout(function() { run(items.showRegistrarInfoIcons); }, 0); + } else if (items.showRegistrarInfoIcons) { + // Only make info icons, do not concat pages. + setTimeout(makeInfoIcons, 0); } + }); }); -function makeInfoIcons(context) { - $('tr.tbon > span.em', context).prepend('hi'); //'); +/** + * Concatenate the pages. + * @param showInfoIcons whether to show the info icons after concatenating the pages. + */ +function run(showInfoIcons) { + var $body = $('body'); + + $body.append(''); + + loadMorePages($body); +} + +function makeInfoIcons() { + var $row, + $a, + $link, + $rows = $('tr.tbon td span.em').parent().parent(), + min, + max; + + if (concatRegistrarResults) { + min = 0; + max = $rows.length - 1; + } else { + min = 1; + max = $rows.length - 2; + } + + for (var i = min; i <= max; i++) { + makeIcon($($rows[i])); + } +} + +function makeIcon($row) { + $a = $row.parent().next().children(':first').children(':first').children(':first') + $link = $(''); + + $row.prepend($link); + $link.attr('data-href', $a.attr('href')); + + // Weird-looking way of making sure that $link's onclick method + // calls showDescription with itself as the parameter. + $link.click( + function($$link) { return function(){ showDescription($$link); }; }($link) + ); } -function loadMorePages (body) { +function showDescription($link) { + + if ($link.attr('data-loaded')) { + + // Description has already been loaded. + // Show/hide the description + $link.next().toggle(); + + } else { + + $.ajax({ + + url: $link.attr('data-href'), + + success: function(data, textStatus, jqXHR) { + var text = '', + regex = /

([\s\S]*?)<\/p>/g, + match; + + // Find all the matches in the received data + while (match = regex.exec(data)) { + text += match[1]; + text += '

'; + } + + $link.after('

' + text + '
'); + $link.attr('data-loaded', true); + }, + + error: function(jqXHR, textStatus, errorThrown) { } + + }); + } + +} + +/** + * Steps that must be taken after all the pages have been loaded. + */ +function finishUp() { + + // Get rid of the Previous Page/Next Page buttons + $('div.otherClasses').parent().parent().parent().parent().parent().parent().remove(); + $('a.otherClasses').parent().parent().parent().remove(); + + if (doMakeInfoIcons) { + makeInfoIcons(); + } +} + +function loadMorePages(body) { var form = body.find('#next_page'); if (form.length === 0) { // This must be the last page. - //console.log("Form not found on this page."); - - // Get rid of the Previous Page/Next Page buttons - $('div.otherClasses').parent().parent().parent().parent().parent().parent().remove(); - $('a.otherClasses').parent().parent().parent().remove(); + finishUp(); return; } @@ -69,6 +154,12 @@ function loadMorePages (body) { success: function(data, textStatus, jqXHR) { var table, rows, len, targetTable; + // Do not load the scripts in the header + // This reduces the number of web requests. + data = data.replace(/[\s\S]*?<\/script>/g, '') + + console.log(data); + // Put the background-loaded page into the hidden div hiddenPages.html(data); @@ -79,8 +170,6 @@ function loadMorePages (body) { targetTable = $('body #classList'); - makeInfoIcons(table); - // Copy over rows from the table of classes from the hidden div $.each(rows, function(index, row) { // Do not copy the first and last row of each table @@ -94,9 +183,7 @@ function loadMorePages (body) { // Load more pages! setTimeout(function(){ loadMorePages(hiddenPages); }, 0); }, - error: function(jqXHR, textStatus, errorThrown) { - //if fails - } + error: function(jqXHR, textStatus, errorThrown) { } }); e.preventDefault(); //STOP default action diff --git a/src/registrar/registrar.css b/src/registrar/registrar.css new file mode 100644 index 0000000..bafdd6e --- /dev/null +++ b/src/registrar/registrar.css @@ -0,0 +1,31 @@ + +tr.tbon td a.info { + display: block; + position: relative; + right: 10px; + bottom: 0px; + width: 30px; + height: 30px; + margin-left: -30px; + margin-right: -30px; + margin-bottom: -30px; + margin-top: 0px; + + background-image: url('chrome-extension://hnkgfpaamopphlecfiacponkgdjefknb/resources/information35.png'); + background-repeat: no-repeat; + background-size: contain; + + z-index: 2; +} + +tr.tbon td div.description { + position: relative; + right: 420px; + bottom: 0px; + width: 400px; + height: 30px; + margin-left: -30px; + margin-right: -30px; + margin-bottom: -30px; + margin-top: 0px; +} \ No newline at end of file diff --git a/src/resources/information35.png b/src/resources/information35.png new file mode 100644 index 0000000000000000000000000000000000000000..8602aa6a266422772faa692af4f1ed75a05fe7d1 GIT binary patch literal 1926 zcmV;12YL93P)sEo!#|jeb#nt@A^udq=6)L)3i?9 zqL!#p1WG_y;wXl~AEi=)h@gm6A~J$hP^wl?RgKaT=!IziNoZ-IK#)yQW7kz3q`Glz z$9HUJeXPCL%$*y;fjVnI?z1iROot=5tJdQDjeDFxiE%l$RlOOa-+%}PL zRkA?J{1RDLEW6y4fz2g!Wm#j9WQtzV3^u-)G~PQq7<=KV-i7geT3*Al7caX%wB|jf>H42K{qidUe|L zKV(|SZx60Nu&3Jd`}!i$ZM#YfEF=y6a#TNh>oY@-o3YO=q~kMu=g8>GEj4l*Z}M;G zn^C&w68gJ@0APgUIB;N$BLt9n(!6uMe5a{E0N%fxJagO0k%P!l=&C|aAFK^*tr7a` z3xx`^i8X^U@rp;niQZI3gAR^>Z8prt1Av~X7z+5_M+cX&=8P9#|4Q)1{fz}%ttJBi-N=2nC7!d@=iOc@Z|Iw@`(vixZV+;| zJ$Pt;qwi~W5&-}qIg0$zrwZM?{jq0TxqJV=AFexkL*Dep>usUhyQ)1;IT<4Y5^>>& zO$AvE+^pJu^pC0Zi5-vKS9Q%}&!;yOW}J3%w}6iyo5>`dh#zX0jjA-Uq|k(F(5o+h znU`;Du9TgmK#9l2mwMP40J~SNUG085_LOe;erw5qSIEnZS{vu%?o#0FM1b zH)B72q^TLedv^0(k3hJ606?DHTiIM$AlU9kB8s7y6#)PhUb192S0);Y#M1Htu8huu&`axCFaFbjr{@nS3Zz$e)j= zNRp>|vhL~Oi>vt<$F?ww8!oFd8`l-y?U1?v6Fb#mTnvZ5sDm$Fh zrL&|^7tt)P*7AYX6=E(DDN0FPXBK-M=NK&aD$)u%WeK9{H199pT07t3$n{p%s2`BcNb-AvGgbdzHH|;WdP1iCVOJ4 zF=~LLYKn#Ha`^O2C7?7gmz|8ei{hA;MqwVzlCTI}JS?SBF&bdy!5{pnB!^v!DRCwdpInOfbj zCfIRexa0h+a@Il-&V+Puq(E|+-skF@QU3JBKa9P4{dGQ*@u$n>eZ%wWSbdRLo-45E z;>ep{4R%t7E7@##!ieZ1qQrBe9J;^_25SPk{hsgpOaJafD= zp7`)o-*_;a2*Awe>BEiE0A+vMSR(CS-SFnnAJ+c5xoqfu9Am5Yrlt=Jbbq_{yG!cX)+h{n-R;4Jx9l!mLJ*Ncz!PN z<1(-C`HjV*->SdCfDfjXxtX~B$~~3B&wP&$W$nUq;Ydh2PwuU3-c%;E`6RN{FOj-Z z4}Z%#iTDJ<5sm}5s8BVc7}1zU=Tw7DMijlTYb<{1c-Oq;BTbq34_6Y<9?p*VOaK4? M07*qoM6N<$f}hXDXaE2J literal 0 HcmV?d00001