0

I would like to be able to redirect a page to a subdomain using a chrome extension. After numerous attempts, nothing works.

Ideally, I want:
"https://www.facebook.com" -> "https://www.facebook.com/groups/123456789" and "https://www.facebook.com/*" to be left alone (where * is a wild card).

To me it should be simple as there are no variables, but it doesn't appear to be. A further complication is that I started learning java yesterday, I am okay at html, c++, c, vb etc.

Why? Because I use facebook to keep up to date with solutions to problem sheets and things on my course, but my news feed is a) Distracting and b) rubbish.

If you can help you'd be a star (if you could comment your code that'd be awsome as I can learn a bit then as well) :D

So far I have, but it doesn't work :(

manifest.json

{
"name": "Tabber",
"manifest_version" : 2,
"version": "1.0",
"description": "MyExtension",
"chrome_url_overrides": {
    "*www.facebook.com*": "my.html"
},
"permissions": [
    "tabs"
]
}

my.html

<!DOCTYPE html>
<html>
<head>
<head>
    <meta http-equiv="refresh"content="0;URL=http://www.google.com">
</head>
</head>
<body>    
</body>
</html>
Aaron
  • 7,015
  • 2
  • 13
  • 22
  • possible duplicate of [Chrome Redirect Extension](http://stackoverflow.com/questions/12065029/chrome-redirect-extension) – Rob W Apr 09 '14 at 13:12

1 Answers1

1

First, your mistakes.

Second, how to do it.

It's relatively easy to do with a content script. You don't need a tabs permission even, just the host permission for Facebook.

Manifest:

{
  "name": "Tabber",
  "manifest_version" : 2,
  "version": "1.0",
  "description": "MyExtension",
  "content_scripts": [
    {
      matches: ["*://www.facebook.com/*"],
      js: ["myscript.js"],
      runAt: "document_start"
    }
  ]
}

Then, your script will be injected when any tab navigates to any facebook page.

The script itself should check the URL and navigate away if needed:

// myscript.js
if(window.location.pathname == "/") {
  window.location.replace("https://www.facebook.com/groups/123456789");
}

I don't use FB myself, so not sure if it will break any logic; but it's what you were trying to do.

Xan
  • 74,770
  • 16
  • 179
  • 206