【发布时间】:2015-04-09 04:33:20
【问题描述】:
我正在尝试制作自己的 chrome 扩展,但我只有 html 的基本知识,而 js 对我来说是胡言乱语。所以我在乞求帮助。
我有这种网址:
http://www.website.com/blabla/number1/number2/blabla/number3_orig.extension
http://www.website.com/blabla/11912/57294/blabla/001_orig.png
我正在尝试制作一个扩展程序,允许增加或减少该 url 中的数字并同时显示网页,并且我希望能够在 url 末尾选择扩展名(png 或 jpg) .
http://postimg.org/image/40cevbqlh/full/
“+”表示当前数字加一,“-”表示当前数字减一,单选按钮更改扩展名为.png或.jpg
示例: 我有这个网址:
http://www.website.com/blabla/00000/00000/blabla/000_orig.png
当我点击第一个“+”时,这个网址应该会打开:
http://www.website.com/blabla/00001/00000/blabla/000_orig.png
现在我点击该网址应该打开的第二个“+”:
http://www.website.com/blabla/00001/00001/blabla/000_orig.png
现在我点击“.jpg 单选按钮”这个网址应该打开:
http://www.website.com/blabla/00001/00001/blabla/000_orig.jpg
现在当我点击第二个“-”时,这个网址应该会打开:
http://www.website.com/blabla/00001/00000/blabla/000_orig.jpg
等等等等……
我能够制作这个代码:
manifest.json
{
"name": "Name",
"version": ".1",
"description": "Description",
"background": {
"page":"bg.html"
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Click here!"
},
"manifest_version": 2,
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["content.js"]
}
],
"permissions": ["tabs"]
}
popup.html
<!doctype html>
<!--
This page is shown when the extension button is clicked, because the
"browser_action" field in manifest.json contains the "default_popup" key with
value "popup.html".
-->
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: https://developer.chrome.com/extensions/contentSecurityPolicy
-->
<script src="popup.js"></script>
</head>
<body>
<button id="plus1">+</button>
<button id="plus2">+</button>
<button id="plus3">+</button>
<br/>
<button id="minus1">-</button>
<button id="minus2">-</button>
<button id="minus3">-</button>
<br/>
<input type="radio" name="extension" value="png">.png
<input type="radio" name="extension" value="jpg">.jpg
</body>
</html>
bg.html
<html>
<script src="redirect.js"></script>
</html>
popup.js
??? I dont know what code should be here...
redirect.js
??? I dont know what code should be here...
content.js
??? I dont know what code should be here...
【问题讨论】:
标签: javascript regex google-chrome url