Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var urlBox = document.getElementById('URL');
- var subButton = document.getElementById('subButton');
- var urlBox = document.getElementById('URL');
- displayWatchList();
- subButton.onclick = function(e){
- e.preventDefault();
- var url = urlBox.value;
- chrome.storage.sync.get(url, function(data){
- var items = data[url];
- if(items){
- console.log('hi');
- items[1] = true;
- items[3] = 1;
- items[4] = 2;
- chrome.storage.sync.set({[url]: items});
- displayWatchList();
- }
- else{
- chrome.storage.sync.set({[url]: [0, true, false, 1, 2 ,0]});
- displayWatchList();
- }
- });
- };
- function displayWatchList(){
- chrome.storage.sync.get(null, function(data){
- for(var item in data){
- if(data[item][1]){
- var tableRow = document.createElement('tr');
- var tableUrl = document.createElement('td');
- var allowFor = document.createElement('td');
- var declineFor = document.createElement('td');
- var allowMins = document.createElement('input');
- var declineMins = document.createElement('input');
- allowMins.setAttribute('type', 'number');
- allowMins.setAttribute('class', 'numInput');
- declineMins.setAttribute('type', 'number');
- declineMins.setAttribute('class', 'numInput');
- allowFor.appendChild(allowMins);
- declineFor.appendChild(declineMins);
- allowFor.value = data[item][3];
- declineFor.value = data[item][4];
- tableUrl.textContent = item;
- tableRow.appendChild(tableUrl);
- tableRow.appendChild(allowFor);
- tableRow.appendChild(declineFor);
- watchTable.appendChild(tableRow);
- }
- }
- });
- }
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="popup.css">
- </head>
- <body>
- <form action = "/form-page" method = "post">
- <label for = 'URL'>URL:</label> <input type="text" id = "URL" name="site_url">
- <button type = "submit" id = 'subButton'>Submit</button>
- </form>
- <div id = 'watchTable'>
- <table>
- <tr>
- <th>Website Name</th>
- <th>Access Website For:</th>
- <th>Block Website For:</th>
- </tr>
- </table>
- </div>
- <script src = "popup.js"></script>
- </body>
- </html>
- var items;
- var mins;
- chrome.runtime.onInstalled.addListener(function(){
- console.log("App Installed");
- });
- var web_list =[];
- chrome.tabs.onUpdated.addListener(function(tabId, info, tab){
- if(info.status == 'complete'){
- var site = tab.url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4];
- checkClose(tab.id, site);
- logTime();
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
- web_list.push(tabs[0].url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4]); //get url of site and then extract host name
- });
- }
- });
- chrome.tabs.onActivated.addListener(function(){
- logTime();
- chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
- web_list.push(tabs[0].url.match('^(([^:/?#]+):)?(//([^/?#]*))?')[4]);
- //get url of site and then extract host name
- });
- });
- function logTime(){
- if (web_list.length > 0){
- var url = web_list[web_list.length - 1];
- chrome.storage.sync.get('time', function(data){
- chrome.storage.sync.get(url, function(data){
- items = data[url];
- console.log(items);
- });
- if(items){
- item[0] = 0;
- chrome.storage.sync.set({[url]: items});
- }
- else{
- chrome.storage.sync.set({[url]: [0, false, false, 0, 0, 0]});
- }
- });
- }
- }
- function checkClose(id, site){
- chrome.storage.sync.get(site, function(data){
- var arr = data[site];
- console.log(site);
- console.log(arr);
- if(arr && arr[1]){
- if(arr[2]){
- console.log('jesus');
- }
- else{
- arr[5] = 'yo';
- arr[2] = true;
- chrome.storage.sync.set({[site]: arr});
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment