
function injectScript() {
  var script = document.createElement('script'),
      body = document.getElementsByTagName('body')[0],
      workerscript = document.createElement('script');

  script.src = chrome.runtime.getURL('dime.logger.js');
  script.type = 'text/javascript';
  script.setAttribute('chrome', 'true');
  // Appending to body
  body.appendChild(script);

  window.addEventListener('message', (event) => {
    if(event.data && event.data.type && event.data.type === 'fromInjectedJStoHook') {
      console.log('hooking is done')
      chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
        //console.log(`tabs.status = ${request.data.status}`)
        if (request.data.url) {
            console.log('url changed, parsing page')
            window.postMessage({
              type: 'fromContentScriptNotifyURLChanged',
              message: request.data.url
            }, '*');
        }
      });

      window.addEventListener('message', function(event) {
        if(event.data && event.data.type && event.data.type === 'compiledResult') {
          let {HTML, abstract, pageURL, hyperLinks, imgURLs, metaTags, openGraphProtocol, tags, text, title, frequentTerms} = event.data.pageData
          let dataWithDimeStructure = {
            '@type': 'DesktopEvent',
            type: 'http://www.semanticdesktop.org/ontologies/2010/01/25/nuao/#UsageEvent',
            actor: 'DiMe browser extension',
            start: Date.now(),
            targettedResource: {
              title: title,
              '@type': 'Document',
              type: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#PlainTextDocument',
              tags: tags,
              isStoredAs: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#RemoteDataObject',
              mimeType: 'application/json',
              plainTextContent: JSON.stringify({HTML, abstract, hyperLinks, imgURLs, metaTags, frequentTerms, openGraphProtocol, text}),
              uri: pageURL,
            }
          }
          //var data = JSON.stringify(dataWithDimeStructure, undefined, 4)
          //var blob = new Blob([data], {type: 'text/json'}),
          //    e    = document.createEvent('MouseEvents'),
          //    a    = document.createElement('a')
          //a.download = 'hiit.json'
          //a.href = window.URL.createObjectURL(blob)
          //a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
          //e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
          //a.dispatchEvent(e)
          chrome.runtime.sendMessage({dataWithDimeStructure: dataWithDimeStructure}, (response) => {
              //console.log(response)
          });

        }
      });

    }

  });
}
const notLocalhost = /^http:\/\/\w+(\.\w+)*(:[0-9]+)?\/?(\/[.\w]*)*$/
//Requesting variables from background page
chrome.runtime.sendMessage({variable: 'enabled'}, function(response) {
  if (response.enabled)
    chrome.storage.local.get(['skipSites', 'disconnected'], (items)=> {
      let {skipSites, disconnected} = items
      if (disconnected)
        console.log('disconnected with dime, do nothing.')
      else
        if (skipSites.indexOf(window.location.href.replace(/.*?:\/\//g, "")) === -1 && !notLocalhost.test(window.location.href)) {
          console.log(`site is not in the filter list: ${skipSites}, continue`)
          injectScript();
        }
    })
  else
    console.log('dime extension is disable by user, wont do anything.')
})

@@ -1,9 +1,8 @@
-%0A
 function
@@ -21,19 +21,19 @@
 t() %7B%0A  
-var
+let
  script 
@@ -66,23 +66,22 @@
 script')
-,
 %0A  
-   
+let
  body = 
@@ -124,65 +124,8 @@
 )%5B0%5D
-,%0A      workerscript = document.createElement('script');%0A
 %0A  s
@@ -175,17 +175,16 @@
 ger.js')
-;
 %0A  scrip
@@ -254,32 +254,8 @@
 ue')
-;%0A  // Appending to body
 %0A  b
@@ -279,17 +279,16 @@
 cript);%0A
-%0A
   window
@@ -320,18 +320,23 @@
 e', 
+function
 (event)
- =%3E
  %7B%0A 
@@ -399,2735 +399,418 @@
 == '
-fromInjectedJStoHook') %7B%0A      console.log('hooking is done')%0A      chrome.runtime.onMessage.addListener((request, sender, sendResponse) =%3E %7B%0A        //console.log(%60tabs.status = $%7Brequest.data.status%7D%60)%0A        if (request.data.url) %7B%0A            console.log('url changed, parsing page')%0A            window.postMessage(%7B%0A              type: 'fromContentScriptNotifyURLChanged',%0A              message: request.data.url%0A            %7D, '*');%0A        %7D%0A      %7D);%0A%0A      window.addEventListener('message', function(event) %7B%0A        if(event.data && event.data.type && event.data.type === 'compiledResult') %7B%0A          let %7BHTML, abstract, pageURL, hyperLinks, imgURLs, metaTags, openGraphProtocol, tags, text, title, frequentTerms%7D = event.data.pageData%0A          let dataWithDimeStructure = %7B%0A            '@type': 'DesktopEvent',%0A            type: 'http://www.semanticdesktop.org/ontologies/2010/01/25/nuao/#UsageEvent',%0A            actor: 'DiMe browser extension',%0A            start: Date.now(),%0A            targettedResource: %7B%0A              title: title,%0A              '@type': 'Document',%0A              type: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#PlainTextDocument',%0A              tags: tags,%0A              isStoredAs: 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo/#RemoteDataObject',%0A              mimeType: 'application/json',%0A              plainTextContent: JSON.stringify(%7BHTML, abstract, hyperLinks, imgURLs, metaTags, frequentTerms, openGraphProtocol, text%7D),%0A              uri: pageURL,%0A            %7D%0A          %7D%0A          //var data = JSON.stringify(dataWithDimeStructure, undefined, 4)%0A          //var blob = new Blob(%5Bdata%5D, %7Btype: 'text/json'%7D),%0A          //    e    = document.createEvent('MouseEvents'),%0A          //    a    = document.createElement('a')%0A          //a.download = 'hiit.json'%0A          //a.href = window.URL.createObjectURL(blob)%0A          //a.dataset.downloadurl =  %5B'text/json', a.download, a.href%5D.join(':')%0A          //e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)%0A          //a.dispatchEvent(e)%0A          chrome.runtime.sendMessage(%7BdataWithDimeStructure: dataWithDimeStructure%7D, (response) =%3E %7B%0A              //console.log(response)%0A          %7D);%0A%0A        %7D%0A      %7D);%0A%0A    %7D%0A%0A  %7D);%0A%7D%0Aconst notLocalhost = /%5Ehttp:%5C/%5C/%5Cw+(%5C.%5Cw+)*(:%5B0-9%5D+)?%5C/?(%5C/%5B.%5Cw%5D*)*$/%0A//Requesting variables from background page%0Achrome.runtime.sendMessage(%7Bvariable: 'enabled'%7D, function(response) %7B%0A  if (response.enabled)%0A    chrome.storage.local.get(%5B'skipSites', 'disconnected'%5D, (items)=%3E %7B%0A      let %7BskipSites, disconnected%7D = items%0A      if (disconnected)%0A        console.log('disconnected with dime, do nothing.')%0A      else%0A  
+pageDataWithDimeStructure') %7B%0A      chrome.runtime.sendMessage(%7BdataWithDimeStructure: event.data.payload%7D)%0A    %7D%0A  %7D)%0A%7D%0Achrome.runtime.onMessage.addListener((request, sender, sendResponse) =%3E %7B%0A  if (request.data.url) %7B%0A    console.log('tab url changed')%0A    chrome.storage.local.get(%5B'skipSites'%5D, (v)=%3E %7B%0A      let %7BskipSites%7D = v%0A      const notLocalhost = /%5Ehttp:%5C/%5C/%5Cw+(%5C.%5Cw+)*(:%5B0-9%5D+)?%5C/?(%5C/%5B.%5Cw%5D*)*$/%0A
     
@@ -931,18 +931,16 @@
 n.href))
- %7B
 %0A       
@@ -936,26 +936,26 @@
 f))%0A        
-  
+//
 console.log(
@@ -1020,18 +1020,16 @@
         
-  
 injectSc
@@ -1044,99 +1044,16 @@
     
-    %7D%0A    %7D)%0A  else%0A    console.log('dime extension is disable by user, wont do anything.')
+%7D)%0A  %7D
 %0A%7D)%0A
+%0A%0A

switch to sync storage