diff --git a/tools/YTtoLBRY.css b/tools/YTtoLBRY.css new file mode 100644 index 0000000..805af29 --- /dev/null +++ b/tools/YTtoLBRY.css @@ -0,0 +1,36 @@ +body { + width: 400px; + text-align: center; + background-color: #191a1c; + color: whitesmoke; + + left: 50%; + top: 50%; +} + +.container { + display: block; + text-align: center; + margin: 0 auto; + width: 80%; + margin-bottom: 15px; + +} + +.goButton { + border-radius: 5px; + background-color: #075656; + border: 4px solid #075656; + color: whitesmoke; + font-weight: 400; + padding: 4px 15px; + margin-right: 25px; + text-align: center; +} + + +label { + font-size: 1.1rem; + margin: 15px auto; + display: block; +} diff --git a/tools/YTtoLBRY.html b/tools/YTtoLBRY.html new file mode 100644 index 0000000..ae56185 --- /dev/null +++ b/tools/YTtoLBRY.html @@ -0,0 +1,20 @@ + + + + + + Subscribtion Converter + + + + + + + + + + + + + diff --git a/tools/YTtoLBRY.js b/tools/YTtoLBRY.js new file mode 100644 index 0000000..169e528 --- /dev/null +++ b/tools/YTtoLBRY.js @@ -0,0 +1,91 @@ +console.log("YouTube To LBRY finder!"); +var ytChannelsString = ""; +var lbryChannelsString = ""; +let lbryArray = []; +var toCheck = []; +let tempJson = {"0":0}; +var subconv; +var goButton; +var lbryChannelList; + +window.addEventListener('load', (event) => { + subconv = document.getElementById("subconv"); + goButton = document.getElementById("go-button"); + lbryChannelList = document.getElementById("lbry-channel-list"); + + goButton.addEventListener('click', () => onGoClicked()); +}); + +function getFile(file) { + const reader = new FileReader(); + reader.addEventListener('load', (event) => { + var content = event.target.result; + content = content.replace('',''); + content = content.replace('',''); + content = content.replace('/>',' '); + splitChannels = content.split("="); + toCheck = []; + for (var i = 0; i <= splitChannels.length-1; i++) { + tempChannel = splitChannels[i]; + if (tempChannel.indexOf("outline text")>=29) { + toCheck[toCheck.length] = tempChannel.slice(0, tempChannel.indexOf("outline text")-5); + } + } + lbryAPIrequest(); + }); + reader.readAsText(file); +} + +function onGoClicked() { + if (subconv.files.length > 0) { + getFile(subconv.files[0]); + } +} + +function lbryAPIrequest() { + // Clear current channel list + while (lbryChannelList.lastElementChild) { + lbryChannelList.removeChild(lbryChannelList.lastElementChild); + } + + chrome.storage.local.get('redirect', redirect => { + validateChannels(toCheck, redirect.redirect); + }); +} + +function validateChannels(channels, redirect) { + const requestSize = 325; + var channelsString = ""; + for (let i = 0; i < channels.length && i < requestSize; i++) { + channelsString += `${channelsString.length > 0 ? ',' : ''}${channels[i]}` + } + request = new XMLHttpRequest(); + request.open("GET", `https://api.lbry.com/yt/resolve?channel_ids={${channelsString}}`); + request.send(); + request.onload = () => { + if (request.status == 200) { + var testChannels = JSON.parse(request.responseText).data.channels; + Object.keys(testChannels).map((testChannelKey) => { + let testChannel = testChannels[testChannelKey]; + if (testChannel != null) { + let link = `${redirect === "lbry.tv" ? "https://lbry.tv/" : "lbry://"}${testChannel}`; + let li = document.createElement('li'); + let a = document.createElement('a'); + a.href = link; + a.innerText = link; + li.appendChild(a); + lbryChannelList.appendChild(li); + } + }); + } + if (requestSize < channels.length) { + channels.splice(0, requestSize); + validateChannels(channels, redirect); + } + } +} + +chrome.storage.local.get('redirect', redirect => { + console.log(redirect); +})