Skip to content

Commit

Permalink
v0.1.9-alpha.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ahaoboy committed Jun 20, 2024
1 parent 1be3e2c commit 8eff9b5
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 14 deletions.
6 changes: 2 additions & 4 deletions babel/hack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fnVar = (t) =>
t.functionExpression(null, [], t.blockStatement([])),
),
]);
module.exports = function ({ types: t }) {
return {
module.exports = ({ types: t }) => ({
visitor: {
FunctionDeclaration(path) {
path.node.body?.body?.unshift?.(fnVar(t));
Expand All @@ -15,5 +14,4 @@ module.exports = function ({ types: t }) {
// path.node.body?.body?.unshift?.(fnVar(t))
},
},
};
};
});
61 changes: 61 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"semicolons": "asNeeded"
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 2
},
"files": {
"ignore": [
"*.sh",
"target",
"output",
"*.stackdump",
"*.ps1",
"*.yaml",
"*.js",
"./mpv-*/dist/**",
"./mpv-*/es/**",
"node_modules",
".vscode",
".github",
"./common",
"./coverage",
"./html",
"CHANGELOG.json"
]
},
"linter": {
"enabled": true,
"rules": {
"style": {
"noNonNullAssertion": "off",
"noParameterAssign": "off"
},
"complexity": {
"noBannedTypes": "off"
},
"suspicious": {
"noArrayIndexKey": "off",
"noRedeclare": "off",
"noUnsafeDeclarationMerging": "off",
"noExplicitAny": "off",
"noImplicitAnyLet": "off",
"noFallthroughSwitchClause": "off",
"noAssignInExpressions": "off"
},
"correctness": {
"useExhaustiveDependencies": "off"
},
"recommended": true
}
}
}
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mpv-easy/mpsm-scripts",
"version": "0.1.9-alpha.3",
"version": "0.1.9-alpha.4",
"files": ["bin", "dist", "es5", "bundle", "readme.md", "package.json"],
"description": "@mpv-easy/mpsm-scripts",
"main": "./dist/index.js",
Expand All @@ -14,7 +14,8 @@
"dev:copy": "chokidar 'src/**/*' -c 'pnpm run build && pnpm run copy' -d 3000 --initial",
"copy": "cp -r ./es5/*.js $MPV_SCRIPT_DIR/",
"es5": "babel --presets @babel/preset-env ./bundle -d es5 --plugins ./babel/hack.js",
"lint": "biome check --apply-unsafe ./",
"lint:fix": "biome lint ./ --write --unsafe",
"lint": "biome check --apply-unsafe ./",
"format": "biome format --write ./"
},
"keywords": [],
Expand All @@ -33,10 +34,10 @@
"@babel/core": "^7.23.9",
"@babel/preset-env": "^7.23.9",
"@babel/preset-typescript": "^7.23.3",
"@biomejs/biome": "^1.5.3",
"@mpv-easy/autoload": "0.1.9-alpha.8",
"@biomejs/biome": "^1.8.0",
"@mpv-easy/autoload": "0.1.9-alpha.8",
"@mpv-easy/plugin": "0.1.9-alpha.8",
"@mpv-easy/tool": "0.1.9-alpha.8",
"@mpv-easy/tool": "0.1.9-alpha.9",
"@mpv-easy/polyfill": "0.1.9-alpha.8",
"@types/node": "^20.12.12",
"@chokidar-napi/chokidar": "0.1.3",
Expand Down
5 changes: 3 additions & 2 deletions scripts.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"mpv-easy-es5": "https://github.com/mpv-easy/mpv-easy/releases/latest/download/mpv-easy-es5.js",
"mpv-easy-es6": "https://github.com/mpv-easy/mpv-easy/releases/latest/download/mpv-easy-es6.js",
"sub2clipboard": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/sub2clipboard.js",
"mpv-easy-es6": "https://github.com/mpv-easy/mpv-easy/releases/latest/download/mpv-easy-es6.js",
"sub2clipboard": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/sub2clipboard.js",
"firequalizer15": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/firequalizer15.meta.lua",
"visualizer": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/visualizer.meta.lua",
"autocrop": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autocrop.meta.lua",
"acompressor": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/acompressor.meta.lua",
"autoload": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload.js",
"autoload-sub": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload-sub.js",
"speed": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/speed.js",
"open-file-dialog": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/open-file-dialog.meta.lua",
"vlc-aspect-ratio": "https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/vlc-aspect-ratio.js"
Expand Down
7 changes: 7 additions & 0 deletions src/autoload-sub.meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// ==UserScript==
// @name autoload-sub
// @version 0.1.1
// @description Automatically load sub files
// @author mpv-easy
// @downloadURL https://github.com/mpv-easy/mpsm-scripts/releases/latest/download/autoload-sub.js
// ==/UserScript==
80 changes: 80 additions & 0 deletions src/autoload-sub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import "@mpv-easy/polyfill";
import {
isHttp,
fetch,
SubtitleTypes,
getenv,
getFileName,
joinPath,
writeFile,
commandv,
getPropertyNative,
type TrackItem,
existsSync,
observeProperty,
getProperty,
registerEvent,
mkdir,
} from "@mpv-easy/tool";

registerEvent("file-loaded", autoloadSub);
observeProperty("path", "string", autoloadSub);
registerEvent("start-file", autoloadSub);

export function autoloadSub() {
const path = getProperty("path");
if (!path?.length) {
return;
}

const trackList = (getPropertyNative<TrackItem[]>("track-list") || []).filter(
(i) => i.type === "sub",
);
if (isHttp(path)) {
const list = SubtitleTypes.map((i) => {
const s = path.split(".").slice(0, -1);
s.push(i);
return s.join(".");
});
const tmp = getenv("TMPDIR") || getenv("TMP") || getenv("tmp") || "./";
for (const url of list) {
const name = getFileName(url);
if (!name?.length) {
continue;
}

if (trackList.find((i) => i.title === name)) {
continue;
}

try {
const resp = fetch(url);

if (resp.status !== 200 || !resp.text?.length) {
continue;
}

const subPath = joinPath(tmp, name);
writeFile(subPath, resp.text);
commandv("sub-add", subPath);
} catch (e) {
mkdir("./aaaa");
}
}
} else {
const list = SubtitleTypes.map((i) => {
const s = path.split(".").slice(0, -1);
s.push(i);
return s.join(".");
});
for (const url of list) {
const name = getFileName(url);
if (trackList.find((i) => i.title === name)) {
continue;
}
if (existsSync(url)) {
commandv("sub-add", url);
}
}
}
}
6 changes: 3 additions & 3 deletions src/sub2clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@mpv-easy/polyfill";
import { setClipboard, print, observeProperty } from "@mpv-easy/tool";

observeProperty("sub-text", "string", (_, v) => {
if (v) {
setClipboard(v);
}
if (v) {
setClipboard(v);
}
});

0 comments on commit 8eff9b5

Please sign in to comment.