Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPRedirect: new redirect userscript for Tampermonkey/Greasemonkey #88

Closed
JayBrown opened this issue May 11, 2017 · 2 comments
Closed

IPRedirect: new redirect userscript for Tampermonkey/Greasemonkey #88

JayBrown opened this issue May 11, 2017 · 2 comments

Comments

@JayBrown
Copy link
Contributor

JayBrown commented May 11, 2017

The redirect script ipfs-userscript linked in this repo wasn't working for me, neither the original version, nor the current one, which I had a little help in, so I tried to do it myself. I'm new to JS, so it's in part inspired by the JS code in the currently dormant Safari extension (ipfs-catcher).

https://github.com/JayBrown/IPRedirect

Since there's no quick toggle on/off, the script should eventually test if the local node is running, i.e. something like a quick curl to localhost:8080. If it returns "000", the node is inactive, otherwise it's running, i.e. returning "404". (I had already tried it with jQuery.ajax, but it wasn't stable; at first try it didn't redirect, then afterwards it did, but when the node was disabled, it still wanted to redirect to localhost.) So if anyone knows how to easily check for node enabled/disabled in a userscript, I'd be very grateful.

See also the related question here: http://stackoverflow.com/questions/43901231/ipfs-javascript-check-for-404-status-from-localhost8080-to-determine-in-brow

@lidel
Copy link
Member

lidel commented May 11, 2017

Maybe something like this?

let check = new Image();
check.onload = onlineHook;
check.onerror = offlineHook;
// this image is a part of WebUI (load with current timestamp to disable caching)
check.src = 'http://127.0.0.1:8080/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ/8f70e85e85c6a23c75c6862292d871c0.png?d=' + escape(Date());

function onlineHook() {
  // enable redirect
}
function offlineHook() {
  // disable redirect
}

@JayBrown
Copy link
Contributor Author

Brilliant! This seems to have worked… thank you. :) I've left out offlineHook, though. I assume only onlineHook will be necessary.

I've already updated the script, so if you want to include this in this repo's README.md instead of ipfs-userscript (repo: ipfs-redirect-userscript), be my guest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants