[Extension] Add AD plus extension 86/156586/9
authormin7.choi <min7.choi@samsung.com>
Thu, 19 Oct 2017 04:46:12 +0000 (13:46 +0900)
committerjaekuk lee <juku1999@samsung.com>
Tue, 31 Oct 2017 01:02:28 +0000 (01:02 +0000)
This patch adds a new extension 'AD plus'
Show ads before running the app.

Change-Id: I0118f58252afc920d6d45fb5339bb8285d1de16b
Signed-off-by: min7.choi <min7.choi@samsung.com>
wrt/wrt_support/extensions_repo/ad_plus/adv.mp4 [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/adv1.mp4 [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/adv2.mp4 [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/background.js [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/body.png [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/contentscript.js [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/header.png [new file with mode: 0755]
wrt/wrt_support/extensions_repo/ad_plus/manifest.json [new file with mode: 0755]

diff --git a/wrt/wrt_support/extensions_repo/ad_plus/adv.mp4 b/wrt/wrt_support/extensions_repo/ad_plus/adv.mp4
new file mode 100755 (executable)
index 0000000..b330dab
Binary files /dev/null and b/wrt/wrt_support/extensions_repo/ad_plus/adv.mp4 differ
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/adv1.mp4 b/wrt/wrt_support/extensions_repo/ad_plus/adv1.mp4
new file mode 100755 (executable)
index 0000000..9a7aaa3
Binary files /dev/null and b/wrt/wrt_support/extensions_repo/ad_plus/adv1.mp4 differ
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/adv2.mp4 b/wrt/wrt_support/extensions_repo/ad_plus/adv2.mp4
new file mode 100755 (executable)
index 0000000..7f430c8
Binary files /dev/null and b/wrt/wrt_support/extensions_repo/ad_plus/adv2.mp4 differ
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/background.js b/wrt/wrt_support/extensions_repo/ad_plus/background.js
new file mode 100755 (executable)
index 0000000..fdc3e97
--- /dev/null
@@ -0,0 +1,9 @@
+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!"});
+    }
+  });
+});
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/body.png b/wrt/wrt_support/extensions_repo/ad_plus/body.png
new file mode 100755 (executable)
index 0000000..c707779
Binary files /dev/null and b/wrt/wrt_support/extensions_repo/ad_plus/body.png differ
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/contentscript.js b/wrt/wrt_support/extensions_repo/ad_plus/contentscript.js
new file mode 100755 (executable)
index 0000000..dc9a175
--- /dev/null
@@ -0,0 +1,132 @@
+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);
+  }
+});
+
+var app_id = location.href.split('/');
+
+if (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;
+  var flag = 0;
+
+  var adv_div = document.createElement('div');
+
+  var video = document.createElement('video');
+  video.src = '../../extensions_repo/ad_plus/adv2.mp4';
+  video.type = 'video/mp4';
+  video.autoplay = 'true';
+
+  console.log('screen.availHeight : ', screen.availHeight);
+  console.log('screen.availWidth : ', screen.availWidth);
+
+  var video_style = document.createAttribute("style");
+  video_style.nodeValue = 'position: absolute; top:0px; left:0px; width:'+screen.availWidth+'px; height:'+screen.availHeight+'px; z-index:1; color:white; font-size:30px; font-weight:bold';
+  video.setAttributeNode(video_style);
+
+  adv_div.appendChild(video);
+
+  var text_div = document.createElement('div');
+  text_div.id = 'text';
+  var text_style = document.createAttribute('style');
+  text_style.nodeValue = 'position: absolute; top:'+(screen.availHeight - 100)+'px; left:'+(screen.availWidth - 250)+'px; width:200px; height:50px; z-index:3; color:white; font-size:20px; font-weight:bold';
+  text_div.setAttributeNode(text_style);
+  var text = document.createTextNode(cnt + ' 초 후에 SKIP 가능');
+  text_div.appendChild(text);
+
+  var skip_div = document.createElement('div');
+  var skip_style = document.createAttribute("style");
+  skip_style.nodeValue = 'background-color:rgba(0, 0, 0, .3); text-align: center; position: absolute; top:'+(screen.availHeight - 100)+'px; left:'+(screen.availWidth - 250)+'px; width:100px; height:33px; z-index:5; color:white; font-size:30px; font-weight:bold';
+  skip_div.setAttributeNode(skip_style);
+  skip_div.innerHTML = 'SKIP';
+
+  var text_div1 = document.createElement('div');
+  text_div1.id = 'text1';
+  var text_style = document.createAttribute('style');
+  text_style.nodeValue = 'position: absolute; top:10px; left:10px; width:300px; height:50px; z-index:3; color:white; font-size:20px; font-weight:bold';
+  text_div1.setAttributeNode(text_style);
+  var text1 = document.createTextNode('광고 영상이 재생 중입니다.');
+  text_div1.appendChild(text1);
+
+  skip_div.onclick = function() {
+    console.log('clicked skip ');
+    document.getElementsByTagName('body')[0].removeChild(skip_div);
+    document.getElementsByTagName('body')[0].removeChild(adv_div);
+    document.getElementsByTagName('body')[0].removeChild(text_div1);
+    clearInterval(timer);
+  };
+
+  document.getElementsByTagName('body')[0].appendChild(adv_div);
+  document.getElementsByTagName('body')[0].appendChild(text_div);
+  document.getElementsByTagName('body')[0].appendChild(text_div1);
+
+  var timer = setInterval(function() {
+    cnt--;
+
+    console.log('ended :' + video.ended);
+
+    if(video.ended == true) {
+      document.getElementsByTagName('body')[0].removeChild(adv_div);
+      document.getElementsByTagName('body')[0].removeChild(skip_div);
+      document.getElementsByTagName('body')[0].removeChild(text_div1);
+      clearInterval(timer);
+    }
+
+    if(cnt < 1 && flag == 0) {
+      flag = 1;
+      document.getElementsByTagName('body')[0].removeChild(text_div);
+      document.getElementsByTagName('body')[0].appendChild(skip_div);
+      //document.getElementById('skip').focus();
+    }
+    else if(flag == 0) {
+      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
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/header.png b/wrt/wrt_support/extensions_repo/ad_plus/header.png
new file mode 100755 (executable)
index 0000000..17c818b
Binary files /dev/null and b/wrt/wrt_support/extensions_repo/ad_plus/header.png differ
diff --git a/wrt/wrt_support/extensions_repo/ad_plus/manifest.json b/wrt/wrt_support/extensions_repo/ad_plus/manifest.json
new file mode 100755 (executable)
index 0000000..b82022d
--- /dev/null
@@ -0,0 +1,18 @@
+{
+  "name": "ad_plus",
+  "description": "Show ads before the app starts",
+  "version": "1.0",
+  "background": {
+    "scripts": ["background.js"],
+    "persistent": false
+  },
+  "content_scripts": [
+    {
+      "matches": [
+        "<all_urls>"
+      ],
+      "js": ["contentscript.js"]
+    }
+  ],
+  "manifest_version": 2
+}