简体   繁体   English

修改chrome扩展名并且不破坏扩展名

[英]modify chrome extension and don't destroy the extension

After modifying a chrome extension'js code and restart the chrome,the modified chrome extension becomes destroyed. 修改chrome扩展程序的js代码并重新启动chrome后,修改后的chrome扩展程序将被销毁。 Three months ago,i did the same thing to the same extension and it worked well. 三个月前,我对相同的扩展名做了同样的事情,并且效果很好。

This time i get a new computer and the lastest version chrome(46.0.2490.86 m),but once i modify the extension's source code it get destroyed. 这次我得到一台新计算机和最新版本的chrome(46.0.2490.86 m),但是一旦我修改了扩展程序的源代码,它就会被销毁。

Here is the source code and the extension. 这是源代码和扩展名。 PS:i think it's because chrome refuse me to modify its origin extension code. PS:我认为是因为chrome拒绝我修改其原点扩展码。

extension name:totop. 扩展名:totop。 extension function:Add a back to top button and go to bottom button on every page 扩展功能:在每页上添加一个返回顶部按钮并转到底部按钮

i just modify "500" to "100" to accelerate its speed. 我只是将“ 500”修改为“ 100”以加快其速度。

the main script.js: 主要的script.js:

 $("head").prepend("<style>._BackToTopPlus{width:35px;height:35px;border-radius:5px; position:fixed; right:10px; cursor:pointer; background-repeat:no-repeat; background-position:50% 50%; background-color:#000; opacity:.1;transition:opacity .2s ease-in-out;z-index:99999;}._BackToTopPlus:hover{opacity:.5}</style>");
var level=$(window).height()/2-50;
$("body").append("<div class='_BackToTopPlus' style='background-image:url(data:img/png;base64,R0lGODlhEgAUAJEAAAAAAP///////wAAACH5BAEAAAIALAAAAAASABQAAAImjI+py+IPo4xmWmRpyq5dFkzgoY3VY5KS9ykcKy6vnMEr3W417hQAOw==);top:"+(level-40)+"px;'></div>").append("<div class='_BackToTopPlus' style='background-image:url(data:img/png;base64,R0lGODlhEgAUAJEAAAAAAP///////wAAACH5BAEAAAIALAAAAAASABQAAAIqlB2peX27nINKNsoswnrTLmABKJKcJH5PGl3siKZdabZgWN2rzuPv/yoAADs=);top:"+(level+5)+"px;'></div>");
var jsq=0;
$("._BackToTopPlus").eq(0).click(function(){$("body").animate({scrollTop:0},500);}).mouseover(function(){
    jsq=setInterval(function(){
        $("body").scrollTop($("body").scrollTop()-1);
    },20);
}).mouseout(function(){clearInterval(jsq);jsq=null;});
$("._BackToTopPlus").eq(1).click(function(){$("body").animate({scrollTop:$(document).height()},500);}).mouseover(function(){
    jsq=setInterval(function(){
        $("body").scrollTop($("body").scrollTop()+1);
    },20);
}).mouseout(function(){clearInterval(jsq);jsq=null;});

spend 1 years, i myself get the answer ! 用了1年,我自己得到了答案!

chrome browser will auto detect all its extension online to guarantee safety, so after editing one extension file, chrome browser will report error on the extension. chrome浏览器将在线自动检测所有扩展名以确保安全,因此在编辑一个扩展名文件后,chrome浏览器将报告该扩展名错误。

solution

  1. copy all extension files out, edit files what we need, delete other irrelevant files, modify manifest.json. 复制所有扩展文件,编辑所需文件,删除其他无关文件,修改manifest.json。
  2. start chrome develop mode 启动chrome开发模式
  3. load the extension 加载扩展

example

old extension files include 旧的扩展名文件包括

  • _locales _locales
  • _metadata _元数据
  • jq.js jq.js
  • logo.png logo.png
  • manifest.json manifest.json
  • script.js script.js

new extension files 新的扩展名文件

files we need is: 我们需要的文件是:

  • jq.js jq.js
  • logo.png logo.png
  • manifest.json manifest.json
  • script.js script.js

edit sript.js to get function we need. 编辑sript.js以获取我们需要的功能。 edit manifest.json, mine manifest.json like: 编辑manifest.json,mine manifest.json,如下所示:

``` ```

{
   "content_scripts": [ {
      "js": [ "jq.js", "script.js" ],
      "matches": [ "http://*/*", "https://*/*" ]
   } ],
   "icons": {
      "128": "logo.png"
   },
   "manifest_version": 2,
   "name": "ToTop",
   "version": "1.0.0.0"
}

``` ```

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM