热门标签 | 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);

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


推荐阅读
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文详细介绍了Linux中进程控制块PCBtask_struct结构体的结构和作用,包括进程状态、进程号、待处理信号、进程地址空间、调度标志、锁深度、基本时间片、调度策略以及内存管理信息等方面的内容。阅读本文可以更加深入地了解Linux进程管理的原理和机制。 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 本文讲述了作者通过点火测试男友的性格和承受能力,以考验婚姻问题。作者故意不安慰男友并再次点火,观察他的反应。这个行为是善意的玩人,旨在了解男友的性格和避免婚姻问题。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
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社区 版权所有