热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

删除垃圾代码前的一些保存

删除垃圾代码前的一些保存content_script.jswindow.addEventListener(load,function(){chrome.extension.se

删除垃圾代码前的一些保存

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=‘
‘+txt+‘
‘;
} 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);

删除垃圾代码前的一些保存


推荐阅读
  • React基础篇一 - JSX语法扩展与使用
    本文介绍了React基础篇一中的JSX语法扩展与使用。JSX是一种JavaScript的语法扩展,用于描述React中的用户界面。文章详细介绍了在JSX中使用表达式的方法,并给出了一个示例代码。最后,提到了JSX在编译后会被转化为普通的JavaScript对象。 ... [详细]
  • 本文介绍了django中视图函数的使用方法,包括如何接收Web请求并返回Web响应,以及如何处理GET请求和POST请求。同时还介绍了urls.py和views.py文件的配置方式。 ... [详细]
  • 本文介绍了2015年九月八日的js学习总结及相关知识点,包括参考书《javaScript Dom编程的艺术》、js简史、Dom、DHTML、解释型程序设计和编译型程序设计等内容。同时还提到了最佳实践是将标签放到HTML文档的最后,并且对语句和注释的使用进行了说明。 ... [详细]
  • 第8章 使用外部和内部链接
    8.1使用web地址LearnAboutafricanelephants. ... [详细]
  • ①页面初始化----------收到客户端的请求,产生相应页面的Page对象,通过Page_Init事件进行page对象及其控件的初始化.②加载视图状态-------ViewSta ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Python瓦片图下载、合并、绘图、标记的代码示例
    本文提供了Python瓦片图下载、合并、绘图、标记的代码示例,包括下载代码、多线程下载、图像处理等功能。通过参考geoserver,使用PIL、cv2、numpy、gdal、osr等库实现了瓦片图的下载、合并、绘图和标记功能。代码示例详细介绍了各个功能的实现方法,供读者参考使用。 ... [详细]
  • 在编写业务代码时,常常会遇到复杂的业务逻辑导致代码冗长混乱的情况。为了解决这个问题,可以利用中间件模式来简化代码逻辑。中间件模式可以帮助我们更好地设计架构和代码,提高代码质量。本文介绍了中间件模式的基本概念和用法。 ... [详细]
  • 本文介绍了前端人员必须知道的三个问题,即前端都做哪些事、前端都需要哪些技术,以及前端的发展阶段。初级阶段包括HTML、CSS、JavaScript和jQuery的基础知识。进阶阶段涵盖了面向对象编程、响应式设计、Ajax、HTML5等新兴技术。高级阶段包括架构基础、模块化开发、预编译和前沿规范等内容。此外,还介绍了一些后端服务,如Node.js。 ... [详细]
  • 延迟注入工具(python)的SQL脚本
    本文介绍了一个延迟注入工具(python)的SQL脚本,包括使用urllib2、time、socket、threading、requests等模块实现延迟注入的方法。该工具可以通过构造特定的URL来进行注入测试,并通过延迟时间来判断注入是否成功。 ... [详细]
  • JavaScript和HTML之间的交互是经由过程事宜完成的。事宜:文档或浏览器窗口中发作的一些特定的交互霎时。能够运用侦听器(或处置惩罚递次来预订事宜),以便事宜发作时实行相应的 ... [详细]
  • JavaWeb中读取文件资源的路径问题及解决方法
    在JavaWeb开发中,读取文件资源的路径是一个常见的问题。本文介绍了使用绝对路径和相对路径两种方法来解决这个问题,并给出了相应的代码示例。同时,还讨论了使用绝对路径的优缺点,以及如何正确使用相对路径来读取文件。通过本文的学习,读者可以掌握在JavaWeb中正确找到和读取文件资源的方法。 ... [详细]
author-avatar
陆寥频
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有