删除垃圾代码前的一些保存
2014-09-21 07:55
106 查看
删除垃圾代码前的一些保存
content_script.js
content_script.js
// window.addEventListener("load", function() { // chrome.extension.sendMessage({ // type: "dom-loaded", // data: { // myProperty: "this is so cool!!!----One-Time Requests,communication happens only once" // } // }); // }, true); //=======================this is for the hover======================= (function(window){ var document = window.document, body = document.body, a = document.getElementsByTagName('a'), //for get a href,returns a live HTMLCollection of elements with the given tag name currentLength = a.length, currentLinks = [], displayTimeout, normalURL, zIndex=100, container, containerLabel, button, size = 1.0, rate, on, showModel, hovernow, //to judge whether the mouse point is on hovering delayTime; loadSettings(); addEvents(); drawWindow(); //从storage中获得值,进行初始化工作 function loadSettings(){ chrome.storage.sync.get([ 'hoverLinkPosition', 'hoverLinkOffsetX', 'hoverLinkOffsetY', 'hoverLinkNormal', 'hoverLinkDelayTime', 'hoverLinkRate', 'on', 'model'], function(data){ rate = data.hoverLinkRate; moveBox(data.hoverLinkPosition, data.hoverLinkOffsetX, data.hoverLinkOffsetY); normalURL = data.hoverLinkNormal; delayTime = data.hoverLinkDelayTime; on = data.on; showModel = data.model; // console.log("log in content"+on); }); } function moveBox(s,x,y){ // var str = "Hello world!"; // var res = str.substr(1, 4) var a = s.substring(0,s.indexOf('-')), b = s.substr(s.indexOf('-')+1); // ?? // console.log(a); //top // console.log(b); //right // container.setAttribute('style','z-index:'+zIndex+';'); container.style[a]=y+'px'; //style里面存放json ,所以a,b是key container.style[b]=x+'px'; container.style['overflow']='scroll'; container.style['max-width']='1450px'; container.style['max-height']='400px'; container.style['-webkit-transform'] = 'scale('+rate+')'; container.style['-webkit-transform-origin'] = '0px 0px'; //"-webkit-transform: scale(0.43);-webkit-transform-origin: 200px 100px;overflow:scroll" } function addEvents(){ for(var i=currentLength-1;i>=0;i--){ addEvent(a[i]); currentLinks.push(a[i]); //放入数组中 } } function addEvent(a){ a.addEventListener('mouseover',linkMouseOver,false);//当mouseover触发,调用linkMouseOver a.addEventListener('mouseleave',linkMouseOut,false); $('body').on('click',mouseclick); } function linkMouseOver(event){ var url = this.href; //this应该指a标签 //console.log("client :top->"+event.clientY+" left->"+event.clientX +" offset:top->"+window.pageYOffset+" left->"+window.pageXOffset); container.style['top'] = event.clientY+'px' container.style['left'] = event.clientX+'px'; hovernow = 1; displayTimeout = setTimeout(function(){ displayBox(); setTimeout(function(){ mouseOver(url); },1000); //mouseOver(url); },delayTime) } function linkMouseOut(event){ console.log('now mouseout'); hovernow = 0; clearTimeout(displayTimeout); //Prevent the function set with the setTimeout() to execute if(!container){ //$("body").removeChild(container); body.removeChild(container); }else{ container.style.display= 'none'; } } function mouseOver(url){ if(hovernow==1){ console.log('now mouseover'); $.post('http://gozoom4235.appspot.com/highlight.php',{url:url},function(webdata){ //displayBox(); if(showModel==1){ insertLabel(webdata); }else{ showWord(webdata); } }) } } function mouseclick(event){ clearTimeout(displayTimeout); if(!container){ //$("body").removeChild(container); body.removeChild(container); }else{ container.style.display= 'none'; } } function displayBox() { container.innerHTML = "loading....."; if(on==1){ body.appendChild(container);//appendChild会把之前所有关于container的以html节点方式加入,到这里才会在html中显示 $(container).show('fast'); } } function requestURL(link){ sendMessage({ hoverLink:'findURL', url:link }); //jason } function sendMessage(message){ //chrome.runtime.sendMessage(message,empty); } function empty(){} //========unknow function drawWindow() { //画一个框子显示usrl var all = document.getElementsByTagName('*'); for ( var i=all.length; i >= 0; i-- ) { var style = getComputedStyle(all[i]); if ( !style ) continue; var z = parseInt(style.getPropertyValue('z-index')); if ( z > zIndex ) zIndex = z+1; } var _container = document.createElement('div'), _label = document.createElement('div'); _button = document.createElement('button'); _button.onclick = function(){ size = size + 0.1; set(); }; _button2 = document.createElement('button'); _button2.onclick = function(){ size = size - 0.1; set(); }; _container.id = 'hoverLinkContainer'; _container.style.zIndex = zIndex; _container.innerHTML = 'Loading...'; _label.id = 'hoverLinkLabel'; //_label.innerHTML = 'Loading...'; //预先设置的显示 //_label.style.cssText = "-webkit-transform: scale(1.0);-webkit-transform-origin: 0px 0px;"; //for containLabel init _container.appendChild(_label); containerLabel=_label; //_label变成节点了? _button.id = "buttonLarg"; _button2.id = "buttonSmal"; _button.style['background']="white"; _button.style['font-color']="black"; _button.style['margin-top']="5px"; button = _button; container = _container; label = _label; } // function showFinalURL(url){ // insertLabel(url); // } function insertLabel(txt){ //txt=txt.substring(1,txt.length-1); container.innerHTML=txt; //嵌入到文本中(注意是‘’不是“”) //container.innerHTML='<button onclick="zoomout()">enlarger</button><input type="button" id ="button2" value="smaller" onclick="zoomin()"><div>'+txt+'</div>'; } function set() { containerLabel.style.cssText = containerLabel.style.cssText + '; -webkit-transform: scale(' + size + ');-webkit-transform-origin: 0 0;'; } function showWord(webdata){ $.post('http://gozoom4235.appspot.com/body.php',{webdata:webdata},function(data){ //http://localhost/body.php console.log(data); insertLabel(data);}); } })(window);
相关文章推荐
- 如何批量删除电脑上的一些垃圾文件
- js禁止保存网页的一些代码
- 保存写了一天代码(注意,程序有一些问题)
- asp.net mvc3:自己编写的一些垃圾代码,删前分享(2013-01-18)
- android网络获取图片并保存在本地和获取手机SD卡中的图片显示到ImageView上及利用代码删除图片
- 删除数据,一些案例实在的说明一些代码
- 最近在练习数据结构,会在这上面保存一些基本的代码
- 地磅称量系统之(40) 实现称量管理界面上的添加、修改、删除、保存、取消按钮的代码
- Xcode 中代码编辑和删除的一些技巧
- 用JS清除word保存为html格式后产生的垃圾代码
- tensorflow的一些代码分析(五) tensorflow模型保存和可视化
- 前几天用VC++,获取SQL中的内容并保存,由于不是很熟悉,走了很多弯路,现在总结哈,希望能给需要的人一些帮助。 直接贴代码。
- 这里是笑的博客,以后会用于记录保存一些自己的代码
- ejb3.0 one-one 保存的一些代码
- asp.net mvc3:自己编写的一些垃圾代码,删前分享(2013-11-13)
- 数据结构作业代码保存-2.1 单向循环链表的建立,插入和删除,和指针移动
- java中对文件的一些操作(删除,复制,计算大小..)和一些数学问题代码详解
- 一些页面常见的问题与解决代码
- Remoting基本实现的一些代码样例程序
- 稍不留神产生代码垃圾