localport.js
· 1.3 KiB · JavaScript
Raw
// 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
}();
| 1 | // I wanted a bookmarklet to take me to the local instance of Plex running on my desktop, so Chromecast would function correctly |
| 2 | // (if I used localhost it wouldn't send the correct uri) |
| 3 | // For this I had to get the local ethernet interface IP |
| 4 | // 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 |
| 5 | // May not work on the most popular web browser |
| 6 | var path = prompt("Enter uri (e.g http://{}:32400/web)"); |
| 7 | // var path = "http://{}:32400/web"; |
| 8 | var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection; |
| 9 | RTCPeerConnection && function() { |
| 10 | function c(ip) { |
| 11 | ip in b || (window.location.href = path.replace(/{}/g, ip)) |
| 12 | } |
| 13 | |
| 14 | function d(a) { |
| 15 | a.split("\r\n").forEach(function(a) { |
| 16 | ~a.indexOf("a=candidate") ? "host" === a.split(" ")[7] && c(a.split(" ")[4]) : ~a.indexOf("c=") && c(a.split(" ")[2]) |
| 17 | }) |
| 18 | } |
| 19 | var a = new RTCPeerConnection({ |
| 20 | iceServers: [] |
| 21 | }); |
| 22 | a.createDataChannel("", { |
| 23 | reliable: !1 |
| 24 | }), a.onicecandidate = function(a) { |
| 25 | a.candidate && d("a=" + a.candidate.candidate) |
| 26 | }, a.createOffer(function(b) { |
| 27 | d(b.sdp), a.setLocalDescription(b) |
| 28 | }, function(a) { |
| 29 | console.warn("offer failed", a) |
| 30 | }); |
| 31 | var b = Object.create(null); |
| 32 | b["0.0.0.0"] = !1 |
| 33 | }(); |
z-localport-shortened.js
· 716 B · JavaScript
Raw
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}();
| 1 | 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}(); |