diff --git a/chrome_extension/background.js b/chrome_extension/background.js new file mode 100644 index 0000000..94f5b11 --- /dev/null +++ b/chrome_extension/background.js @@ -0,0 +1,14 @@ +chrome.runtime.onInstalled.addListener(function() { + chrome.storage.sync.set({color: '#3aa757'}, function() { + console.log("The color is green."); + }); + chrome.declarativeContent.onPageChanged.removeRules(undefined, function() { + chrome.declarativeContent.onPageChanged.addRules([{ + conditions: [new chrome.declarativeContent.PageStateMatcher({ + pageUrl: {hostEquals: 'developer.chrome.com'}, + }) + ], + actions: [new chrome.declarativeContent.ShowPageAction()] + }]); + }); + }); \ No newline at end of file diff --git a/chrome_extension/images/get_started128.png b/chrome_extension/images/get_started128.png new file mode 100644 index 0000000..4c1cf87 Binary files /dev/null and b/chrome_extension/images/get_started128.png differ diff --git a/chrome_extension/images/get_started16.png b/chrome_extension/images/get_started16.png new file mode 100644 index 0000000..fb8531c Binary files /dev/null and b/chrome_extension/images/get_started16.png differ diff --git a/chrome_extension/images/get_started32.png b/chrome_extension/images/get_started32.png new file mode 100644 index 0000000..7715223 Binary files /dev/null and b/chrome_extension/images/get_started32.png differ diff --git a/chrome_extension/images/get_started48.png b/chrome_extension/images/get_started48.png new file mode 100644 index 0000000..94ddde9 Binary files /dev/null and b/chrome_extension/images/get_started48.png differ diff --git a/chrome_extension/manifest.json b/chrome_extension/manifest.json new file mode 100644 index 0000000..192a6d2 --- /dev/null +++ b/chrome_extension/manifest.json @@ -0,0 +1,27 @@ +{ + "name": "Extension", + "version": "1.0", + "description": "Build an Extension!", + "permissions": ["activeTab", "declarativeContent", "storage"], + "background": { + "scripts": ["background.js"], + "persistent": false + }, + "page_action": { + "default_popup": "popup.html", + "default_icon": { + "16": "images/get_started16.png", + "32": "images/get_started32.png", + "48": "images/get_started48.png", + "128": "images/get_started128.png" + } + }, + "icons": { + "16": "images/get_started16.png", + "32": "images/get_started32.png", + "48": "images/get_started48.png", + "128": "images/get_started128.png" + }, + "options_page": "options.html", + "manifest_version": 2 + } \ No newline at end of file diff --git a/chrome_extension/options.html b/chrome_extension/options.html new file mode 100644 index 0000000..9e32758 --- /dev/null +++ b/chrome_extension/options.html @@ -0,0 +1,21 @@ + + + + + + +
+
+
+

Choose a different background color!

+
+ + + \ No newline at end of file diff --git a/chrome_extension/options.js b/chrome_extension/options.js new file mode 100644 index 0000000..ae085f2 --- /dev/null +++ b/chrome_extension/options.js @@ -0,0 +1,15 @@ +let page = document.getElementById('buttonDiv'); + const kButtonColors = ['#3aa757', '#e8453c', '#f9bb2d', '#4688f1']; + function constructOptions(kButtonColors) { + for (let item of kButtonColors) { + let button = document.createElement('button'); + button.style.backgroundColor = item; + button.addEventListener('click', function() { + chrome.storage.sync.set({color: item}, function() { + console.log('color is ' + item); + }) + }); + page.appendChild(button); + } + } + constructOptions(kButtonColors); \ No newline at end of file diff --git a/chrome_extension/popup.html b/chrome_extension/popup.html new file mode 100644 index 0000000..c3571db --- /dev/null +++ b/chrome_extension/popup.html @@ -0,0 +1,23 @@ + + + + + + +
+

Select news anywhere on the page to know if It authentic or fake

+
+ + + + \ No newline at end of file diff --git a/chrome_extension/popup.js b/chrome_extension/popup.js new file mode 100644 index 0000000..27cd30c --- /dev/null +++ b/chrome_extension/popup.js @@ -0,0 +1,78 @@ +let sendText = document.getElementById('sendText'); + + sendText.onclick = function(element) { + // chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + // chrome.tabs.executeScript( + // tabs[0].id, + // {code: 'var div=document.createElement("div"); document.body.prepend(div); div.innerText="hey"; div.id="modal1"; div.style.backgroundColor="' + color + '"' + // }); + // }); + + var resp; + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.executeScript( + null, + {code: "window.getSelection().toString()"}, function(selection){ + var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance + var theUrl = ""; + xmlhttp.open("POST", theUrl); + xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); + xmlhttp.send(JSON.stringify({ "text": selection[0] })); + xmlhttp.onreadystatechange = function() { + if (xmlhttp.readyState == 4) { + // JSON.parse does not evaluate the attacker's scripts. + resp = JSON.parse(xmlhttp.responseText); + } + } + } + ); + }); + + var modal = + '' + + var modal_style = + '.modal-header {' + + 'padding: 0px 0px 16px 16px;' + + 'background-color: #5cb85c;' + + 'color: white;' + + '}' + + + '.modal-body {padding: 2px 16px;}' + + + '.modal {' + + 'position: relative;' + + 'background-color: #fefefe;' + + 'margin: auto;' + + 'padding: 0px;' + + 'border: 1px solid #888;' + + 'width: 50%;' + + 'box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);' + + 'animation-name: animatetop;' + + 'animation-duration: 0.4s' + + '}' + + + '@keyframes animatetop {' + + 'from {top: -300px; opacity: 0}' + + 'to {top: 0px; opacity: 1}' + + '}' + + + chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { + chrome.tabs.executeScript( + null, + {code: "var div=document.createElement('div'); document.body.prepend(div); div.innerHTML='"+modal+"'; var style=document.createElement('style'); document.body.prepend(style); style.innerHTML='"+modal_style+"';"} + ); + }); + + }; + \ No newline at end of file