init
This commit is contained in:
commit
1abb00314a
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
build/
|
7
assets/header.txt
Normal file
7
assets/header.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name PipedYT
|
||||
// @version 0.1.0
|
||||
// @description Add a youtube link to piped's UI
|
||||
// @author LordMZTE
|
||||
// @include http*://piped.kavin.rocks/*
|
||||
// ==/UserScript==
|
44
assets/yt.svg
Normal file
44
assets/yt.svg
Normal file
|
@ -0,0 +1,44 @@
|
|||
<svg
|
||||
width="32"
|
||||
height="32"
|
||||
viewBox="0 0 8.4666665 8.4666666"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14, custom)"
|
||||
sodipodi:docname="yt.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#505050"
|
||||
bordercolor="#ffffff"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="0"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="1"
|
||||
inkscape:deskcolor="#505050"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
inkscape:zoom="9.0004138"
|
||||
inkscape:cx="12.277213"
|
||||
inkscape:cy="29.720856"
|
||||
inkscape:window-width="1481"
|
||||
inkscape:window-height="940"
|
||||
inkscape:window-x="2115"
|
||||
inkscape:window-y="129"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
id="rect412"
|
||||
style="fill:#ffffff;stroke-width:6.35;stroke-linejoin:round;stroke-miterlimit:2"
|
||||
d="M 1.9249471 2.1166667 C 1.3386311 2.1166667 0.86661377 2.588684 0.86661377 3.175 L 0.86661377 5.3950195 C 0.86661377 5.9813356 1.3386311 6.4533529 1.9249471 6.4533529 L 6.694165 6.4533529 C 7.2804811 6.4533529 7.7524984 5.9813356 7.7524984 5.3950195 L 7.7524984 3.175 C 7.7524984 2.588684 7.2804811 2.1166667 6.694165 2.1166667 L 1.9249471 2.1166667 z M 2.903182 2.5285278 L 5.7159302 4.1527181 L 2.9026652 5.7763916 L 2.903182 2.5285278 z " />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.7 KiB |
8
build.hxml
Normal file
8
build.hxml
Normal file
|
@ -0,0 +1,8 @@
|
|||
-cp src
|
||||
-main Main
|
||||
-D js_es=6
|
||||
--macro Init.init()
|
||||
|
||||
-resource assets/yt.svg@icon
|
||||
|
||||
-js build/script.js
|
51
hxformat.json
Normal file
51
hxformat.json
Normal file
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"wrapping": {
|
||||
"arrayWrap": {
|
||||
"defaultWrap": "onePerLine",
|
||||
"rules": [
|
||||
{
|
||||
"conditions": [
|
||||
{
|
||||
"cond": "totalItemLength <= n",
|
||||
"value": 50
|
||||
}
|
||||
],
|
||||
"type": "noWrap"
|
||||
}
|
||||
]
|
||||
},
|
||||
"methodChain": {
|
||||
"rules": [
|
||||
{
|
||||
"conditions": [
|
||||
{
|
||||
"cond": "itemCount >= n",
|
||||
"value": 3
|
||||
}
|
||||
],
|
||||
"type": "onePerLine"
|
||||
}
|
||||
]
|
||||
},
|
||||
"callParameter": {
|
||||
"rules": [
|
||||
{
|
||||
"conditions": [
|
||||
{
|
||||
"cond": "itemCount >= n",
|
||||
"value": 3
|
||||
},
|
||||
{
|
||||
"cond": "totalItemLength >= n",
|
||||
"value": 50
|
||||
}
|
||||
],
|
||||
"type": "onePerLine"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"indentation": {
|
||||
"character": " "
|
||||
}
|
||||
}
|
44
src/ButtonAdder.hx
Normal file
44
src/ButtonAdder.hx
Normal file
|
@ -0,0 +1,44 @@
|
|||
import haxe.Resource;
|
||||
import js.Browser.window;
|
||||
import js.Browser.document;
|
||||
import js.Browser.console;
|
||||
|
||||
function addButton() {
|
||||
console.log("looking for places to put PipedYT buttons...");
|
||||
|
||||
var buttonBar = document.querySelector("#app .w-full .flex .ml-auto");
|
||||
|
||||
if (!isVideoPage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonBar == null) {
|
||||
console.warn("Button bar not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (document.getElementById("pipedyt-button") != null) {
|
||||
console.log("PipedYT button already exists, not adding another.");
|
||||
return;
|
||||
}
|
||||
|
||||
var button = document.createAnchorElement();
|
||||
|
||||
var urlSuffix = window.location.pathname + window.location.search;
|
||||
|
||||
button.href = 'https://youtube.com$urlSuffix';
|
||||
button.target = "_blank";
|
||||
button.id = "pipedyt-button";
|
||||
|
||||
button.classList.add("btn");
|
||||
button.classList.add("flex-col");
|
||||
|
||||
button.innerHTML = Resource.getString("icon");
|
||||
|
||||
buttonBar.appendChild(button);
|
||||
console.log('Added PipedYT button to ${button.href}');
|
||||
}
|
||||
|
||||
function isVideoPage():Bool {
|
||||
return window.location.pathname == "/watch" && StringTools.startsWith(window.location.search, "?v=");
|
||||
}
|
9
src/Init.hx
Normal file
9
src/Init.hx
Normal file
|
@ -0,0 +1,9 @@
|
|||
import haxe.macro.Compiler;
|
||||
import haxe.macro.Context;
|
||||
import sys.io.File;
|
||||
|
||||
macro function init() {
|
||||
var header = Std.string(File.read("assets/header.txt").readAll());
|
||||
Compiler.define("source-header", header);
|
||||
return macro {};
|
||||
}
|
30
src/LocationChangeListener.hx
Normal file
30
src/LocationChangeListener.hx
Normal file
|
@ -0,0 +1,30 @@
|
|||
import js.html.MutationRecord;
|
||||
import js.html.Node;
|
||||
import js.html.MutationObserver;
|
||||
import js.Browser.window;
|
||||
|
||||
class LocationChangeListener {
|
||||
var handler:Void->Void;
|
||||
var observer:MutationObserver;
|
||||
var oldHref:String = window.location.href;
|
||||
|
||||
public function new(handler:Void->Void) {
|
||||
this.handler = handler;
|
||||
this.observer = new MutationObserver(onEvent);
|
||||
}
|
||||
|
||||
public function register(node: Node) {
|
||||
var conf = {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
};
|
||||
this.observer.observe(node, conf);
|
||||
}
|
||||
|
||||
function onEvent(_muts: Array<MutationRecord>, _obs:MutationObserver) {
|
||||
if (this.oldHref == window.location.href)
|
||||
return;
|
||||
this.oldHref = window.location.href;
|
||||
this.handler();
|
||||
}
|
||||
}
|
10
src/Main.hx
Normal file
10
src/Main.hx
Normal file
|
@ -0,0 +1,10 @@
|
|||
import ButtonAdder.addButton;
|
||||
import js.Browser.window;
|
||||
import js.Browser.document;
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
window.addEventListener("load", addButton);
|
||||
new LocationChangeListener(addButton).register(document.body);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue