0

I am trying to make my own chrome extension but I have only basic knowledge of html and js is gibberish to me. So I am begging for help.

I have this kind of url:

http://www.website.com/blabla/number1/number2/blabla/number3_orig.extension

http://www.website.com/blabla/11912/57294/blabla/001_orig.png

And I am trying to make an extension which will allow to increase or decrease numbers in that url and show the webpage at the same time and also I want the ability to choose the extension at the end of url (png or jpg).

http://postimg.org/image/40cevbqlh/full/

"+" means current number plus one, and "-" means current number minus one, radio buttons changes the extension .png or .jpg

Example: I have this url:

http://www.website.com/blabla/00000/00000/blabla/000_orig.png 

and when I click the first "+" this url should open:

http://www.website.com/blabla/00001/00000/blabla/000_orig.png 

and now I click the second "+" this url should open:

http://www.website.com/blabla/00001/00001/blabla/000_orig.png 

and now I click the ".jpg radio button" this url should open:

http://www.website.com/blabla/00001/00001/blabla/000_orig.jpg

and now when I click the second "-" this url should open:

http://www.website.com/blabla/00001/00000/blabla/000_orig.jpg 

etc etc...

I was able to make this code:

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...

1 Answers1

0

You can use window.location to change the url.

So you would get the current page location,

var my_url = window.location.href;

Then you could split the address into it's different parts.

var url_split = my_url.split("/");

If your url is of the form: http://www.website.com/blabla/00001/00001/blabla/000_orig.jpg

Then you could get the first number:

var my_num = parseInt(url_split[4]);

Increment it by one.

my_num = my_num + 1;

Then get your last section of the url, and split by it at the '.':

var pic = url_split[7].split(".");

Set pic[2] (picture extension) to whatever you want:

pic[2] = "jpg"; or pic[2] = "png";

Make your new url from the pieces you've made:

var new_url = "http://www.website.com/" + url_split[3] + "/" + my_num + "/" + my_num + "/" url_split[6] + "/" + ... pic[2];

Then redirect to your new url:

window.location.replace( new_url );

Here is a link to the relevant stackoverflow question on redirection with javascript. Link

Community
  • 1
  • 1