Guest User

Untitled

a guest
May 20th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. var urlBox = document.getElementById('URL');
  2. var subButton = document.getElementById('subButton');
  3. var urlBox = document.getElementById('URL');
  4. displayWatchList();
  5.  
  6. subButton.onclick = function(e){
  7. e.preventDefault();
  8. var url = urlBox.value;
  9. chrome.storage.sync.get(url, function(data){
  10. var items = data[url];
  11. if(items){
  12. console.log('hi');
  13. items[1] = true;
  14. items[3] = 1;
  15. items[4] = 2;
  16. chrome.storage.sync.set({[url]: items});
  17. displayWatchList();
  18. }
  19. else{
  20. chrome.storage.sync.set({[url]: [0, true, false, 1, 2 ,0]});
  21. displayWatchList();
  22. }
  23. });
  24. };
  25.  
  26. function displayWatchList(){
  27. chrome.storage.sync.get(null, function(data){
  28. for(var item in data){
  29. if(data[item][1]){
  30. var tableRow = document.createElement('tr');
  31. var tableUrl = document.createElement('td');
  32. var allowFor = document.createElement('td');
  33. var declineFor = document.createElement('td');
  34. var allowMins = document.createElement('input');
  35. var declineMins = document.createElement('input');
  36.  
  37. allowMins.setAttribute('type', 'number');
  38. allowMins.setAttribute('class', 'numInput');
  39. declineMins.setAttribute('type', 'number');
  40. declineMins.setAttribute('class', 'numInput');
  41.  
  42. allowFor.appendChild(allowMins);
  43. declineFor.appendChild(declineMins);
  44. allowFor.value = data[item][3];
  45. declineFor.value = data[item][4];
  46. tableUrl.textContent = item;
  47. tableRow.appendChild(tableUrl);
  48. tableRow.appendChild(allowFor);
  49. tableRow.appendChild(declineFor);
  50. watchTable.appendChild(tableRow);
  51. }
  52. }
  53. });
  54. }
  55.  
  56. <!DOCTYPE html>
  57. <html>
  58. <head>
  59. <link rel="stylesheet" type="text/css" href="popup.css">
  60. </head>
  61. <body>
  62.  
  63. <form action = "/form-page" method = "post">
  64. <label for = 'URL'>URL:</label> <input type="text" id = "URL" name="site_url">
  65. <button type = "submit" id = 'subButton'>Submit</button>
  66. </form>
  67.  
  68.  
  69. <div id = 'watchTable'>
  70. <table>
  71. <tr>
  72. <th>Website Name</th>
  73. <th>Access Website For:</th>
  74. <th>Block Website For:</th>
  75. </tr>
  76. </table>
  77. </div>
  78.  
  79.  
  80. <script src = "popup.js"></script>
  81. </body>
  82. </html>
  83.  
  84. var items;
  85. var mins;
  86.  
  87. chrome.runtime.onInstalled.addListener(function(){
  88. console.log("App Installed");
  89. });
  90.  
  91. var web_list =[];
  92.  
  93. chrome.tabs.onUpdated.addListener(function(tabId, info, tab){
  94.  
  95. if(info.status == 'complete'){
  96. var site = tab.url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4];
  97. checkClose(tab.id, site);
  98. logTime();
  99.  
  100. chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
  101. web_list.push(tabs[0].url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4]); //get url of site and then extract host name
  102. });
  103. }
  104. });
  105.  
  106. chrome.tabs.onActivated.addListener(function(){
  107. logTime();
  108.  
  109. chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
  110. web_list.push(tabs[0].url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4]);
  111. //get url of site and then extract host name
  112. });
  113.  
  114. });
  115.  
  116. function logTime(){
  117. if (web_list.length > 0){
  118. var url = web_list[web_list.length - 1];
  119.  
  120. chrome.storage.sync.get('time', function(data){
  121.  
  122. chrome.storage.sync.get(url, function(data){
  123. items = data[url];
  124. console.log(items);
  125. });
  126.  
  127. if(items){
  128. item[0] = 0;
  129. chrome.storage.sync.set({[url]: items});
  130. }
  131.  
  132. else{
  133. chrome.storage.sync.set({[url]: [0, false, false, 0, 0, 0]});
  134. }
  135. });
  136. }
  137.  
  138. }
  139.  
  140. function checkClose(id, site){
  141.  
  142. chrome.storage.sync.get(site, function(data){
  143. var arr = data[site];
  144. console.log(site);
  145. console.log(arr);
  146.  
  147. if(arr && arr[1]){
  148.  
  149. if(arr[2]){
  150. console.log('jesus');
  151. }
  152.  
  153. else{
  154. arr[5] = 'yo';
  155. arr[2] = true;
  156. chrome.storage.sync.set({[site]: arr});
  157. }
  158.  
  159. }
  160. });
  161. }
Add Comment
Please, Sign In to add comment