[WRT][Extension] Add page action for ad_plus extension 87/160687/8
authorYoungsoo Choi <kenshin.choi@samsung.com>
Fri, 17 Nov 2017 12:05:55 +0000 (21:05 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 21 Nov 2017 02:14:59 +0000 (11:14 +0900)
The page action is implemented for ad_plus.

Change-Id: I6477ceaad95c0eb0ba884b3b94aa49605a432ea0
Signed-off-by: Youngsoo Choi <kenshin.choi@samsung.com>
wrt/wrt_support/extensions_repo/ad_plus/background.js
wrt/wrt_support/extensions_repo/ad_plus/contentscript.js
wrt/wrt_support/extensions_repo/ad_plus/manifest.json

index fdc3e97bf8f1f666fd4862253a35ad5aeda8b42a..574bb53ee0f39deea384f404ca134d853d639035 100755 (executable)
@@ -1,9 +1,6 @@
 chrome.runtime.onConnect.addListener(function(port) {
-  console.assert(port.name == "contentscript");
-  port.onMessage.addListener(function(msg) {
-    if (msg.contentscript == "Hello background!") {
-      console.log('from contentscript : ' + msg.contentscript);
-      port.postMessage({background: "Hello contentscript!"});
-    }
-  });
-});
+  chrome.pageAction.onClicked.addListener(function(tab) {
+    console.log('Send page action from background to contentscript!')
+    port.postMessage({page_action: 'execute'})
+  })
+})
index dc9a175cad3db17122f8922ed6c53e6be09d2e55..d4adf603dd5a09eb5c4cedb9c20a6d8f9339cec7 100755 (executable)
@@ -1,14 +1,53 @@
-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;
@@ -86,47 +125,4 @@ if (app_id[app_id.length - 2] == 'installer' || app_id[app_id.length - 2] == 'ex
       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
+};
index b82022d0e712d9fc916d09015cff81ab7ed42b90..57d529850ec662cc6b600a00284cc347c62546e8 100755 (executable)
@@ -14,5 +14,8 @@
       "js": ["contentscript.js"]
     }
   ],
+  "page_action": {
+    "default_icon": "icon.png"
+  },
   "manifest_version": 2
 }