').hide().fadeIn("slow");
95 | $('#alert').delay(2000).fadeOut(5000, function() {
96 | $(this).remove();
97 | });
98 | }
99 | // handle errors for name ---------------
100 | if (data.errors.domain) {
101 | console.log('there is a domain error.');
102 | $('#domain-list-group').addClass('has-error'); // add the error class to show red input
103 | $('#domain-list-group').append('
' + data.errors.domain + '
'); // add the actual error message under our input
104 | $('form').append('
' + data.errors.domain + '
').hide().fadeIn("slow");
105 | $('#alert').delay(2000).fadeOut(5000, function() {
106 | $(this).remove();
107 | });
108 | }
109 | } else {
110 | // ALL GOOD! just show the success message!
111 | console.log(data.response);
112 | $('form').append('
'}),b.prototype=a.extend({},a.fn.tooltip.Constructor.prototype),b.prototype.constructor=b,b.prototype.getDefaults=function(){return b.DEFAULTS},b.prototype.setContent=function(){var a=this.tip(),b=this.getTitle(),c=this.getContent();a.find(".popover-title")[this.options.html?"html":"text"](b),a.find(".popover-content")[this.options.html?"html":"text"](c),a.removeClass("fade top bottom left right in"),a.find(".popover-title").html()||a.find(".popover-title").hide()},b.prototype.hasContent=function(){return this.getTitle()||this.getContent()},b.prototype.getContent=function(){var a=this.$element,b=this.options;return a.attr("data-content")||("function"==typeof b.content?b.content.call(a[0]):b.content)},b.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")},b.prototype.tip=function(){return this.$tip||(this.$tip=a(this.options.template)),this.$tip};var c=a.fn.popover;a.fn.popover=function(c){return this.each(function(){var d=a(this),e=d.data("bs.popover"),f="object"==typeof c&&c;e||d.data("bs.popover",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.popover.Constructor=b,a.fn.popover.noConflict=function(){return a.fn.popover=c,this}}(window.jQuery),+function(a){"use strict";function b(c,d){var e,f=a.proxy(this.process,this);this.$element=a(c).is("body")?a(window):a(c),this.$body=a("body"),this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",f),this.options=a.extend({},b.DEFAULTS,d),this.selector=(this.options.target||(e=a(c).attr("href"))&&e.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a",this.offsets=a([]),this.targets=a([]),this.activeTarget=null,this.refresh(),this.process()}b.DEFAULTS={offset:10},b.prototype.refresh=function(){var b=this.$element[0]==window?"offset":"position";this.offsets=a([]),this.targets=a([]);var c=this;this.$body.find(this.selector).map(function(){var d=a(this),e=d.data("target")||d.attr("href"),f=/^#\w/.test(e)&&a(e);return f&&f.length&&[[f[b]().top+(!a.isWindow(c.$scrollElement.get(0))&&c.$scrollElement.scrollTop()),e]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){c.offsets.push(this[0]),c.targets.push(this[1])})},b.prototype.process=function(){var a,b=this.$scrollElement.scrollTop()+this.options.offset,c=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight,d=c-this.$scrollElement.height(),e=this.offsets,f=this.targets,g=this.activeTarget;if(b>=d)return g!=(a=f.last()[0])&&this.activate(a);for(a=e.length;a--;)g!=f[a]&&b>=e[a]&&(!e[a+1]||b<=e[a+1])&&this.activate(f[a])},b.prototype.activate=function(b){this.activeTarget=b,a(this.selector).parents(".active").removeClass("active");var c=this.selector+'[data-target="'+b+'"],'+this.selector+'[href="'+b+'"]',d=a(c).parents("li").addClass("active");d.parent(".dropdown-menu").length&&(d=d.closest("li.dropdown").addClass("active")),d.trigger("activate")};var c=a.fn.scrollspy;a.fn.scrollspy=function(c){return this.each(function(){var d=a(this),e=d.data("bs.scrollspy"),f="object"==typeof c&&c;e||d.data("bs.scrollspy",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.scrollspy.Constructor=b,a.fn.scrollspy.noConflict=function(){return a.fn.scrollspy=c,this},a(window).on("load",function(){a('[data-spy="scroll"]').each(function(){var b=a(this);b.scrollspy(b.data())})})}(window.jQuery),+function(a){"use strict";var b=function(b){this.element=a(b)};b.prototype.show=function(){var b=this.element,c=b.closest("ul:not(.dropdown-menu)"),d=b.attr("data-target");if(d||(d=b.attr("href"),d=d&&d.replace(/.*(?=#[^\s]*$)/,"")),!b.parent("li").hasClass("active")){var e=c.find(".active:last a")[0],f=a.Event("show.bs.tab",{relatedTarget:e});if(b.trigger(f),!f.isDefaultPrevented()){var g=a(d);this.activate(b.parent("li"),c),this.activate(g,g.parent(),function(){b.trigger({type:"shown.bs.tab",relatedTarget:e})})}}},b.prototype.activate=function(b,c,d){function e(){f.removeClass("active").find("> .dropdown-menu > .active").removeClass("active"),b.addClass("active"),g?(b[0].offsetWidth,b.addClass("in")):b.removeClass("fade"),b.parent(".dropdown-menu")&&b.closest("li.dropdown").addClass("active"),d&&d()}var f=c.find("> .active"),g=d&&a.support.transition&&f.hasClass("fade");g?f.one(a.support.transition.end,e).emulateTransitionEnd(150):e(),f.removeClass("in")};var c=a.fn.tab;a.fn.tab=function(c){return this.each(function(){var d=a(this),e=d.data("bs.tab");e||d.data("bs.tab",e=new b(this)),"string"==typeof c&&e[c]()})},a.fn.tab.Constructor=b,a.fn.tab.noConflict=function(){return a.fn.tab=c,this},a(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(b){b.preventDefault(),a(this).tab("show")})}(window.jQuery),+function(a){"use strict";var b=function(c,d){this.options=a.extend({},b.DEFAULTS,d),this.$window=a(window).on("scroll.bs.affix.data-api",a.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",a.proxy(this.checkPositionWithEventLoop,this)),this.$element=a(c),this.affixed=this.unpin=null,this.checkPosition()};b.RESET="affix affix-top affix-bottom",b.DEFAULTS={offset:0},b.prototype.checkPositionWithEventLoop=function(){setTimeout(a.proxy(this.checkPosition,this),1)},b.prototype.checkPosition=function(){if(this.$element.is(":visible")){var c=a(document).height(),d=this.$window.scrollTop(),e=this.$element.offset(),f=this.options.offset,g=f.top,h=f.bottom;"object"!=typeof f&&(h=g=f),"function"==typeof g&&(g=f.top()),"function"==typeof h&&(h=f.bottom());var i=null!=this.unpin&&d+this.unpin<=e.top?!1:null!=h&&e.top+this.$element.height()>=c-h?"bottom":null!=g&&g>=d?"top":!1;this.affixed!==i&&(this.unpin&&this.$element.css("top",""),this.affixed=i,this.unpin="bottom"==i?e.top-d:null,this.$element.removeClass(b.RESET).addClass("affix"+(i?"-"+i:"")),"bottom"==i&&this.$element.offset({top:document.body.offsetHeight-h-this.$element.height()}))}};var c=a.fn.affix;a.fn.affix=function(c){return this.each(function(){var d=a(this),e=d.data("bs.affix"),f="object"==typeof c&&c;e||d.data("bs.affix",e=new b(this,f)),"string"==typeof c&&e[c]()})},a.fn.affix.Constructor=b,a.fn.affix.noConflict=function(){return a.fn.affix=c,this},a(window).on("load",function(){a('[data-spy="affix"]').each(function(){var b=a(this),c=b.data();c.offset=c.offset||{},c.offsetBottom&&(c.offset.bottom=c.offsetBottom),c.offsetTop&&(c.offset.top=c.offsetTop),b.affix(c)})})}(window.jQuery);
--------------------------------------------------------------------------------
/js/listform.js:
--------------------------------------------------------------------------------
1 | // Restores select box and checkbox state using the preferences
2 | // stored in chrome.storage.
3 | function restore_options() {
4 | // Use defaults if empty
5 | chrome.storage.sync.get({
6 | piholekey: 'Unset',
7 | piholeurl: 'http://raspberrypi.local/admin/apiext.php'
8 | }, function(items) {
9 | document.getElementById('piholeurl').value = items.piholeurl;
10 | document.getElementById('piholekey').value = items.piholekey;
11 | });
12 | }
13 |
14 | $(document).ready(function() {
15 | restore_options();
16 | // process the form
17 | $('form').submit(function(event) {
18 | // remove old error class and text
19 | $('.form-group').removeClass('has-error');
20 | $('.help-block').remove();
21 | $('.alert').remove();
22 | var formUrl = $('input[name=piholeurl]').val();
23 | console.log('formUrl',formUrl)
24 | var formData = {
25 | // get the form data
26 | 'piholekey': $('input[name=piholekey]').val(),
27 | 'name': $('input[name=name]').val(),
28 | 'email': $('input[name=email]').val(),
29 | 'superheroAlias': $('input[name=superheroAlias]').val()
30 | };
31 |
32 | console.log(formData);
33 |
34 |
35 |
36 | // process the form
37 | $.ajax({
38 | type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
39 | //url : 'http://raspberrypi.local/admin/apiext123.php', // the url where we want to POST
40 | url : formUrl, // the url
41 | data : formData, // our data object
42 | dataType : 'json', // what type of data do we expect back from the server
43 | encode : true
44 | })
45 | // using the done promise callback
46 | .done(function(data) {
47 | // log data to the console so we can see
48 | console.log(data);
49 | // here we will handle errors and validation messages
50 | if ( ! data.success) {
51 | // handle errors for name ---------------
52 | if (data.errors.name) {
53 | $('#name-group').addClass('has-error'); // add the error class to show red input
54 | $('#name-group').append('
' + data.errors.name + '
'); // add the actual error message under our input
55 | }
56 | // handle errors for email ---------------
57 | if (data.errors.email) {
58 | $('#email-group').addClass('has-error'); // add the error class to show red input
59 | $('#email-group').append('
' + data.errors.email + '
'); // add the actual error message under our input
60 | }
61 | // handle errors for superhero alias ---------------
62 | if (data.errors.superheroAlias) {
63 | $('#superhero-group').addClass('has-error'); // add the error class to show red input
64 | $('#superhero-group').append('
' + data.errors.superheroAlias + '
'); // add the actual error message under our input
65 | }
66 | } else {
67 | // ALL GOOD! just show the success message!
68 | // Remove old box
69 | //$('div').remove(".alert");
70 | $('form').append('
' + data.message + '
');
71 | $('div.alert').fadeOut(5000);
72 | // usually after form submission, you'll want to redirect
73 | // window.location = '/thank-you'; // redirect a user to another page
74 | }
75 | })
76 | // using the fail promise callback
77 | .fail(function(data) {
78 | // show any errors
79 | // best to remove for production
80 | console.log(data);
81 | });
82 | // stop the form from submitting the normal way and refreshing the page
83 | event.preventDefault();
84 | });
85 |
86 | });
87 |
88 | document.addEventListener('DOMContentLoaded', restore_options);
--------------------------------------------------------------------------------
/js/options.js:
--------------------------------------------------------------------------------
1 | // Saves options to chrome.storage.sync.
2 | function save_options() {
3 | var color = document.getElementById('color').value;
4 | var likesColor = document.getElementById('like').checked;
5 | chrome.storage.sync.set({
6 | favoriteColor: color,
7 | likesColor: likesColor
8 | }, function() {
9 | // Update status to let user know options were saved.
10 | var status = document.getElementById('status');
11 | status.textContent = 'Options saved.';
12 | setTimeout(function() {
13 | status.textContent = '';
14 | }, 750);
15 | });
16 | }
17 |
18 | // Restores select box and checkbox state using the preferences
19 | // stored in chrome.storage.
20 | function restore_options() {
21 | // Use default value color = 'red' and likesColor = true.
22 | chrome.storage.sync.get({
23 | favoriteColor: 'red',
24 | likesColor: true
25 | }, function(items) {
26 | document.getElementById('color').value = items.favoriteColor;
27 | document.getElementById('like').checked = items.likesColor;
28 | });
29 | }
30 | document.addEventListener('DOMContentLoaded', restore_options);
31 | document.getElementById('save').addEventListener('click',
32 | save_options);
--------------------------------------------------------------------------------
/js/popup.js:
--------------------------------------------------------------------------------
1 | // Restores hidden inputs from chrome storage.
2 | function restore_options() {
3 | // Use defaults if empty
4 | chrome.storage.sync.get({
5 | piholekey: 'Unset',
6 | piholeurl: 'http://raspberrypi.local/admin/apiext.php'
7 | }, function(items) {
8 | document.getElementById('piholeurl').value = items.piholeurl;
9 | document.getElementById('piholekey').value = items.piholekey;
10 | });
11 | }
12 |
13 |
14 | $(document).ready(function() {
15 |
16 | // process the form when button is pressed.
17 | $('form').submit(function(event) {
18 |
19 | // Disable Input while waiting, pi isnt speedy.
20 | // Purge and lock the select box, because im an asshole.
21 | $('#list').attr('disabled', true);
22 | $('#domain').attr('disabled', true);
23 | $('#submitbutton').text('Running...').attr('disabled', true).toggleClass('btn-danger', 'btn-default');
24 |
25 |
26 | var piholekey = $('input[name=piholekey]').val();
27 | var piholeurl = $('input[name=piholeurl]').val();
28 | console.log('key',piholekey);
29 | console.log('url',piholeurl);
30 | console.log('Domain Form Submitted');
31 |
32 | // remove old error class and text
33 | $('.form-group').removeClass('has-error');
34 | $('.help-block').remove();
35 | var domaindata = {
36 | // get the form data
37 | 'piholekey': piholekey,
38 | 'list': $('#list option:selected').val(),
39 | 'domain': $('#domain').val(),
40 | 'action': 'add'
41 | };
42 | console.log(domaindata);
43 | // process the form
44 | $.ajax({
45 | type: 'POST',
46 | url : piholeurl, // the url where we want to POST
47 | data : domaindata, // our data object
48 | dataType : 'json', // what type of data do we expect back from the server
49 | encode : true
50 | })
51 | // using the done promise callback
52 | .done(function(data) {
53 | // log data to the console so we can see
54 | console.log(data);
55 |
56 | // Unlock the form
57 | $('#list').attr('disabled', false);
58 | $('#domain').attr('disabled', false);
59 | $('#submitbutton').text('Add Entry').attr('disabled', false).toggleClass('btn-danger', 'btn-default');
60 |
61 |
62 | // here we will handle errors and validation messages
63 | if ( ! data.success) {
64 | console.log('oops!:');
65 | console.log(data);
66 | // handle key errors
67 | if(data.errors.list) {
68 | console.log('there is a list name error.');
69 | $('form').append('
').hide().fadeIn("slow");
78 | $('#alert').delay(2000).fadeOut("slow", function() {
79 | $(this).remove();
80 | });
81 | }
82 | // handle errors for name ---------------
83 | if (data.errors.domain) {
84 | console.log('there is a domain error.');
85 | $('#domain-list-group').addClass('has-error'); // add the error class to show red input
86 | $('#domain-list-group').append('
' + data.errors.domain + '
'); // add the actual error message under our input
87 | $('form').append('
' + data.errors.domain + '
').hide().fadeIn("slow");
88 | $('#alert').delay(2000).fadeOut("slow", function() {
89 | $(this).remove();
90 | });
91 | }
92 | } else {
93 | // ALL GOOD! just show the success message!
94 | console.log(data.response);
95 | $('form').append('
' + data.message + '
').hide().fadeIn("slow");
96 | // Fade Message Out...
97 | $('#alert').delay(2000).fadeOut("slow", function() {
98 | $(this).remove();
99 | });
100 | // Purge and lock the select box, because im an asshole.
101 | $('#whitedomainlist').attr('disabled', true);
102 | $('#whitedomainlist').empty().append(' -1) {
147 | domain = url.split('/')[2];
148 | }
149 | else {
150 | domain = url.split('/')[0];
151 | }
152 | //find & remove port number
153 | domain = domain.split(':')[0];
154 | // tab.url is only available if the "activeTab" permission is declared.
155 | // If you want to see the URL of other tabs (e.g. after removing active:true
156 | // from |queryInfo|), then the "tabs" permission is required to see their
157 | // "url" properties.
158 | console.assert(typeof url == 'string', 'tab.url should be a string');
159 | callback(domain);
160 | });
161 | }
162 |
163 |
164 |
165 | function renderStatus(statusText) {
166 | document.getElementById('domain').value = statusText;
167 | //document.getElementById('blocklisthost').value = statusText;
168 | }
169 |
170 | document.addEventListener('DOMContentLoaded', function() {
171 | getCurrentTabUrl(function(url) {
172 | renderStatus(url);
173 | });
174 | });
175 |
176 | document.addEventListener('DOMContentLoaded', restore_options);
177 |
--------------------------------------------------------------------------------
/js/settings.js:
--------------------------------------------------------------------------------
1 | // Saves options to chrome.storage.sync.
2 | function save_options() {
3 | var piholeurl = document.getElementById('piholeurl').value;
4 | var piholekey = document.getElementById('piholekey').value;
5 | chrome.storage.sync.set({
6 | piholekey: piholekey,
7 | piholeurl: piholeurl
8 | }, function() {
9 | // Update status to let user know options were saved.
10 | var status = document.getElementById('status');
11 | status.innerHTML = 'Options saved.';
12 | setTimeout(function() {
13 | status.textContent = '';
14 | }, 2000);
15 | });
16 | }
17 |
18 | // Localstorage
19 | function restore_options() {
20 | // Use defaults
21 | chrome.storage.sync.get({
22 | piholekey: '123456789',
23 | piholeurl: 'http://raspberrypi.local/admin/apiext.php'
24 | }, function(items) {
25 | document.getElementById('piholeurl').value = items.piholeurl;
26 | document.getElementById('piholekey').value = items.piholekey;
27 | });
28 | }
29 |
30 | // Empty storage
31 | function clear_options() {
32 | chrome.storage.sync.clear();
33 | }
34 |
35 | document.addEventListener('DOMContentLoaded', restore_options);
36 | document.getElementById('save').addEventListener('click', save_options);
37 | document.getElementById('clear').addEventListener('click', clear_options);
38 |
--------------------------------------------------------------------------------
/js/whitelist.js:
--------------------------------------------------------------------------------
1 | // Restores hidden inputs from chrome storage.
2 | function restore_options() {
3 | // Use defaults if empty
4 | chrome.storage.sync.get({
5 | piholekey: 'Unset',
6 | piholeurl: 'http://raspberrypi.local/admin/apiext.php'
7 | }, function(items) {
8 | document.getElementById('piholeurl').value = items.piholeurl;
9 | document.getElementById('piholekey').value = items.piholekey;
10 | });
11 | }
12 |
13 | $(document).ready(function() {
14 |
15 | // Get Whitelisted domains when user presses button...
16 | $('#getwhitelist').click(function(event) {
17 | var piholekey = $('input[name=piholekey]').val();
18 | var piholeurl = $('input[name=piholeurl]').val();
19 | console.log('key',piholekey);
20 | console.log('button pushed.');
21 |
22 | var whitelistdata = {
23 | 'piholekey': piholekey,
24 | 'list': 'white',
25 | 'action': 'getlist'
26 | }
27 |
28 | $.ajax({
29 | type:'POST',
30 | url: piholeurl,
31 | data: whitelistdata,
32 | dataType: 'json',
33 | success: function( json ) {
34 | $('#whitedomainlist').attr('disabled', false);
35 | // Purge and reset the list.
36 | $('#whitedomainlist').empty().append('').text(value).attr('value', value));
41 | });
42 | }
43 | });
44 | });
45 | // Got Whitelisted domains
46 |
47 | // process the form when button is pressed.
48 | $('form').submit(function(event) {
49 |
50 | var piholekey = $('input[name=piholekey]').val();
51 | var piholeurl = $('input[name=piholeurl]').val();
52 | console.log('key',piholekey);
53 | console.log('url',piholeurl);
54 | console.log('Form Submitted');
55 |
56 | // remove old error class and text
57 | $('.form-group').removeClass('has-error');
58 | $('.help-block').remove();
59 | var deletedata = {
60 | // get the form data
61 | 'piholekey': piholekey,
62 | 'list': 'white',
63 | 'domain': $('#whitedomainlist option:selected').text(),
64 | 'action': 'delete'
65 | };
66 | console.log(deletedata);
67 | // process the form
68 | $.ajax({
69 | type: 'POST',
70 | url : piholeurl, // the url where we want to POST
71 | data : deletedata, // our data object
72 | dataType : 'json', // what type of data do we expect back from the server
73 | encode : true
74 | })
75 | // using the done promise callback
76 | .done(function(data) {
77 | // log data to the console so we can see
78 | console.log(data);
79 | // here we will handle errors and validation messages
80 | if ( ! data.success) {
81 | console.log('oops!:');
82 | console.log(data);
83 | // handle key errors
84 | if(data.errors.list) {
85 | console.log('there is a list name error.');
86 | $('form').append('
').hide().fadeIn("slow");
95 | $('#alert').delay(2000).fadeOut(5000, function() {
96 | $(this).remove();
97 | });
98 | }
99 | // handle errors for name ---------------
100 | if (data.errors.domain) {
101 | console.log('there is a domain error.');
102 | $('#domain-list-group').addClass('has-error'); // add the error class to show red input
103 | $('#domain-list-group').append('
' + data.errors.domain + '
'); // add the actual error message under our input
104 | $('form').append('
' + data.errors.domain + '
').hide().fadeIn("slow");
105 | $('#alert').delay(2000).fadeOut(5000, function() {
106 | $(this).remove();
107 | });
108 | }
109 | } else {
110 | // ALL GOOD! just show the success message!
111 | console.log(data.response);
112 | $('form').append('