<script> window.Connect = function(time){ var bereceive = [], besend = [], a, b; var body = document.body; if(!body){ throw new Error("window.Connect 函数内没有找个 document.body 元素对象"); return; }; if(chrome["extension"]){ a = "plugs",b= "web"; }else{ a = "web",b= "plugs"; }; var loop = window.setInterval(function(){ var p = body.dataset[a];//设置 var w = body.dataset[b]; //读取
//接收来自网页端变量 try{ var j = JSON.parse(w); bereceive.push(j); }catch(e){} body.dataset[b]="";
//判断网页端是否读取了插件端的发送,再判断是否有数据要发送 try{ if(!p && besend.length){ var t = besend.shift(); var s = JSON.stringify(t); body.dataset[a]=s; } }catch(e){} },time||500);