Created
May 1, 2017 05:57
-
-
Save blha303/c35468f56b1f7a57adc96615164ac03d to your computer and use it in GitHub Desktop.
A bookmarklet to redirect to a web service running on the lan interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I wanted a bookmarklet to take me to the local instance of Plex running on my desktop, so Chromecast would function correctly | |
// (if I used localhost it wouldn't send the correct uri) | |
// For this I had to get the local ethernet interface IP | |
// I initiate a connection to 0.0.0.0, then use the data on the connection object to get the interface IP used for that connection | |
// May not work on the most popular web browser | |
var path = prompt("Enter uri (e.g http://{}:32400/web)"); | |
// var path = "http://{}:32400/web"; | |
var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection; | |
RTCPeerConnection && function() { | |
function c(ip) { | |
ip in b || (window.location.href = path.replace(/{}/g, ip)) | |
} | |
function d(a) { | |
a.split("\r\n").forEach(function(a) { | |
~a.indexOf("a=candidate") ? "host" === a.split(" ")[7] && c(a.split(" ")[4]) : ~a.indexOf("c=") && c(a.split(" ")[2]) | |
}) | |
} | |
var a = new RTCPeerConnection({ | |
iceServers: [] | |
}); | |
a.createDataChannel("", { | |
reliable: !1 | |
}), a.onicecandidate = function(a) { | |
a.candidate && d("a=" + a.candidate.candidate) | |
}, a.createOffer(function(b) { | |
d(b.sdp), a.setLocalDescription(b) | |
}, function(a) { | |
console.warn("offer failed", a) | |
}); | |
var b = Object.create(null); | |
b["0.0.0.0"] = !1 | |
}(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:var path=prompt("Enter uri (e.g http://{}:32400/web)");var RTCPeerConnection=window.webkitRTCPeerConnection||window.mozRTCPeerConnection;RTCPeerConnection&&function(){function c(ip){ip in b||(window.location.href=path.replace(/{}/g, ip))}function d(a){a.split("\r\n").forEach(function(a){~a.indexOf("a=candidate")?"host"===a.split(" ")[7]&&c(a.split(" ")[4]):~a.indexOf("c=")&&c(a.split(" ")[2])})}var a=new RTCPeerConnection({iceServers:[]});a.createDataChannel("",{reliable:!1}),a.onicecandidate=function(a){a.candidate&&d("a="+a.candidate.candidate)},a.createOffer(function(b){d(b.sdp),a.setLocalDescription(b)},function(a){console.warn("offer failed",a)});var b=Object.create(null);b["0.0.0.0"]=!1}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment