-var port = chrome.runtime.connect({name: "contentscript"});
-port.postMessage({contentscript: "Hello background!"});
+// Add page action
+var port = chrome.runtime.connect({name: "contentscript"})
+port.postMessage({contentscript: "Hello background!"})
port.onMessage.addListener(function(msg) {
- if (msg.background == "Hello contentscript!") {
- console.log('from background : ' + msg.background);
+ if (msg.background === 'Hello contentscript!') {
+ console.log('from background : ' + msg.background)
}
-});
+ if (msg.page_action === 'execute') {
+ console.log('from background : ' + msg.page_action)
+ if (document.getElementById('modal_div')) {
+ var popup = document.getElementById('modal_div')
+ document.getElementsByTagName('body')[0].removeChild(popup);
+ }
+ else {
+ const DATA_HTML = '<div id="modal_div" style="display: block; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.7);"> \
+ <div id="content_div" style="background-color:rgb(255, 255, 255); position:absolute; width: 800px; height: 800px;"> \
+ <div id="img_header" style="height: 90px; text-align: center;"> \
+ <img src="../../extensions_repo/ad_plus/header.png" style="width: 788px; height: 80px;"> \
+ </div> \
+ <div id="img_body" style="height: 590px; text-align: center;" > \
+ <img src="../../extensions_repo/ad_plus/body.png" style="width: 788px; height: 590px;"> \
+ </div> \
+ <div id="img_footer" style="height: 90px;font-size: 50px; line-height:90px; vertical-align: middle; text-align: center;"> \
+ Link to site : \
+ <a href="http://www.samsung.com/sec/">samsung</a> \
+ </div> \
+ </div> \
+ </div>';
+
+ document.body.insertAdjacentHTML('beforeend', DATA_HTML);
+
+ var top_val = (screen.availHeight / 2) - 400;
+ var left_val = (screen.availWidth / 2) - 400;
+
+ var modal = document.getElementById('modal_div');
+ document.getElementById('content_div').style.top = top_val+'px';
+ document.getElementById('content_div').style.left = left_val+'px';
+
+ modal.style.display = 'block';
+ }
+ }
+})
+
+// Play AD
var app_id = location.href.split('/');
-if (app_id[app_id.length - 2] == 'installer' || app_id[app_id.length - 2] == 'extensions_settings') {
+if (app_id[app_id.length - 2] === 'launcher' ||
+ app_id[app_id.length - 2] === 'installer' ||
+ app_id[app_id.length - 2] === 'extensions_settings') {
console.log('Except for installer and settings.');
} else {
var cnt = 5;
document.getElementById('text').innerHTML = cnt + ' 초 후에 SKIP 가능';
}
}, 1000);
-
- const DATA_HTML = '<div id="modal_div" style="display: block; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.7);"> \
- <div id="content_div" style="background-color:rgb(255, 255, 255); position:absolute; width: 800px; height: 800px;"> \
- <div id="img_header" style="height: 90px; text-align: center;"> \
- <img src="../../extensions_repo/ad_plus/header.png" style="width: 788px; height: 80px;"> \
- </div> \
- <div id="img_body" style="height: 590px; text-align: center;" > \
- <img src="../../extensions_repo/ad_plus/body.png" style="width: 788px; height: 590px;"> \
- </div> \
- <div id="img_footer" style="height: 90px;font-size: 50px; line-height:90px; vertical-align: middle; text-align: center;"> \
- Link to site : \
- <a href="http://www.samsung.com/sec/">samsung</a> \
- </div> \
- </div> \
- </div>';
-
- var setting = 112;
-
- window.onkeydown = function() {
- console.log('keycode : ', event.keyCode);
-
- var key = event.keyCode;
-
- if (key == setting) {
- if (document.getElementById('modal_div')) {
- var popup = document.getElementById('modal_div')
- document.getElementsByTagName('body')[0].removeChild(popup);
- }
- else {
- console.log('in setting');
- document.body.insertAdjacentHTML('beforeend', DATA_HTML);
-
- var top_val = (screen.availHeight / 2) - 400;
- var left_val = (screen.availWidth / 2) - 400;
-
- var modal = document.getElementById('modal_div');
- document.getElementById('content_div').style.top = top_val+'px';
- document.getElementById('content_div').style.left = left_val+'px';
-
- modal.style.display = 'block';
- }
- }
- }
-};
\ No newline at end of file
+};