开发者

Restoring old facebook photo viewer - Chrome extension

开发者 https://www.devze.com 2023-02-10 02:21 出处:网络
If you noticed, facebook has a new photo viewer...It fact, to replace the original photo viewer, you just have to delete the \"&theater\" option at the URL and reload the web page开发者_如何学Pyth

If you noticed, facebook has a new photo viewer... It fact, to replace the original photo viewer, you just have to delete the "&theater" option at the URL and reload the web page开发者_如何学Python. I want to get this automatically done by a chrome extension. Ive already got the code to retrieve the URL:

<html>
<head>
<script>
window.addEventListener("load", windowLoaded, false);
function windowLoaded() {
  chrome.tabs.getSelected(null, function(tab) {
    document.getElementById('currentlink').innerHTML = tab.url;
  });
}
</script></head>
<body>
<p id="currentlink">Loading ...</p>
</body>
</html>

I can't get to delete the "&theater" from the string and then reloading with the new edited URL (without the &theater)

Thanks in advance.


I made a fiddle for this: http://jsfiddle.net/ArkahnX/LxkZs/2/ (function from http://snipplr.com/view.php?codeview&id=799) below, does the same as you had before, except it pastes all variables except theater back into the URL. From there, you can do what you want with the URL. If tab.url == the new url, then you shouldnt reload the page, or whatever else you require the extension to do.

<html>
<head>
<script>
function getUrlVars(url) {
    var vars = [],
        hash;
    //get URL variables
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
    //get domain
    var domain = url.split("?")[0];
    for (var i = 0; i < hashes.length; i++) {
        //separate variable and parameter
        hash = hashes[i].split('=');
        //get everything but theater
        if (hash[0] !== "theater") {
            vars.push(hash[0]);
            var index = vars.indexOf(hash[0]);
            vars[index] = hash[0]+"="+hash[1];
        }
    }
    //mash it all back together
    return domain+"?"+vars.join("?");
}
window.addEventListener("load", windowLoaded, false);
function windowLoaded() {
  chrome.tabs.getSelected(null, function(tab) {
    document.getElementById('currentlink').innerHTML = getUrlVars(tab.url);
      if(tab.url === getUrlVars(tab.url)) {
          //do nothing
      } else {
          //do something
      }
  });
}
</script></head>
<body>
<p id="currentlink">Loading ...</p>
</body>
</html>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号