Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymous committed May 5, 2024
1 parent 149fcb1 commit 1a05cd5
Show file tree
Hide file tree
Showing 45 changed files with 5,475 additions and 920 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"rules": {
"no-extra-semi": "off",
"@typescript-eslint/no-extra-semi": "off",
"no-inner-declarations": "off"
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-inner-declarations": "off",
"no-constant-condition": ["error", { "checkLoops": false }]
}
}
35 changes: 35 additions & 0 deletions .tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# vim: set fenc=utf-8 ft=taskini:
# see: https://github.com/skywind3000/asynctasks.vim/wiki/Task-Config

# define a new task named "file-build"
[file-build]

# shell command, use quotation for filenames containing spaces
# check ":AsyncTaskMacro" to see available macros
command=npm run compileIntoSingleFile "$(VIM_FILEPATH)"

# working directory, can change to $(VIM_ROOT) for project root
cwd=$(VIM_FILEDIR)

# output mode, can be one of quickfix and terminal
# - quickfix: output to quickfix window
# - terminal: run the command in the internal terminal
output=quickfix

# this is for output=quickfix only
# if it is omitted, vim's current errorformat will be used.
errorformat=%f:%l:%m

# save file before execute
save=1


[file-install]
command:typescript=npm run installScript "$(VIM_FILEPATH)"
cwd=$(VIM_FILEDIR)
save=2
[file-reinstall]
command:typescript=npm run compileIntoSingleFile "$(VIM_FILEPATH)" && npm run installScript "$(VIM_FILEPATH)"
cwd=$(VIM_FILEDIR)
save=2

28 changes: 7 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Scripts for TamperMonkey
# UserScripts for TamperMonkey

## Commands

Expand All @@ -8,25 +8,11 @@ npm run build
```

```sh
# Build single script
npm run compileIntoSingleFile path/to/script
# Build specified scripts
npm run compileIntoSingleFile path/to/script1.ts path/to/script2.ts
```

## User scripts

### Zhihu tweaker

- 移除生成的关键词搜索链接蓝字高亮
- 移除重定向
- 回答显示创建时间和最后修改时间
- 首页-关注页面 `header` 显示 "我的收藏" 和 "我关注的问题"
- 问题页面 显示 "查看问题日志" 按钮, 提问者, 问题创建时间和最后修改时间
- 咨询页面 显示 "打开对话页面" 按钮

### PlaybackRate Controller

目前仅支持B站

-`s`调整基础播放速度为1或2(默认为1)
-`1-9`调整播放速度为相应倍速,再按一次恢复为基础播放速度
- 按住`a`调整为4倍播放速度, 松开恢复为基础播放速度
```sh
# install specified scripts
npm run installScript path/to/script1.ts path/to/script2.ts
```
35 changes: 35 additions & 0 deletions auto-imports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import
export {}
declare global {
const UserScriptStorage: typeof import('./src/utils/storage')['UserScriptStorage']
const _debugger: typeof import('./src/utils/debug')['_debugger']
const awayFromBottom: typeof import('./src/utils/scroll')['awayFromBottom']
const download: typeof import('./src/utils/download')['download']
const enableAutoTurningToNextPage: typeof import('./src/utils/navigating')['enableAutoTurningToNextPage']
const enableHorizontalScroll: typeof import('./src/utils/scroll')['enableHorizontalScroll']
const enableMiddleClickToDownload: typeof import('./src/utils/download')['enableMiddleClickToDownload']
const getPathname: typeof import('./src/utils/navigating')['getPathname']
const inPage: typeof import('./src/utils/navigating')['inPage']
const isLeftclick: typeof import('./src/utils/download')['isLeftclick']
const isMiddleclick: typeof import('./src/utils/download')['isMiddleclick']
const isRecordWithAtLeastOneAddedHTMLElement: typeof import('./src/utils/observer')['isRecordWithAtLeastOneAddedHTMLElement']
const mutationObserver: typeof import('./src/utils/observer')['mutationObserver']
const nearlyScrolledToBottom: typeof import('./src/utils/scroll')['nearlyScrolledToBottom']
const onNearlyScrolledToBottom: typeof import('./src/utils/scroll')['onNearlyScrolledToBottom']
const openInTab: typeof import('./src/utils/navigating')['openInTab']
const redirectedFromAnotherTab: typeof import('./src/utils/navigating')['redirectedFromAnotherTab']
const scrollToBottom: typeof import('./src/utils/scroll')['scrollToBottom']
const scrollToBottomAndScrollBack: typeof import('./src/utils/scroll')['scrollToBottomAndScrollBack']
const selectElementAsync: typeof import('./src/utils/selectElementAsync')['default']
const wait: typeof import('./src/utils/wait')['default']
}
// for type re-export
declare global {
// @ts-ignore
export type { Response_GM_XMLHttpRequest } from 'src/types'
import('src/types')
}
72 changes: 72 additions & 0 deletions dist/pager_bundled.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ==UserScript==
// @name Pager
// @version 0.0.1
// @match https://cn.bing.com/search*
// @match https://www.bing.com/search*
// @grant none
// @description
// ==/UserScript==
"use strict";
const _debugger = {
on: false,
enable() {
this.on = true;
},
disable() {
this.on = false;
},
log(...data) {
this.on && console.log(data);
},
logForce(...data) {
console.log(data);
},
};

/**
* Promise-based `setTimeout`
*/
async function wait(time) {
function execute(resolve) {
setTimeout(resolve, time);
}
return new Promise(execute);
}

function nearlyScrolledToBottom(offset = 1) {
return window.innerHeight + Math.ceil(window.scrollY) + offset >= document.body.scrollHeight;
}
function onNearlyScrolledToBottom(callback, options) {
const { offset = 1, cooldown = 100 } = { ...options };
let cooledDown = true;
window.addEventListener("scroll", async () => {
if (cooledDown && nearlyScrolledToBottom(offset)) {
if (cooldown) {
cooledDown = false;
callback(cooldown);
await wait(cooldown);
cooledDown = true;
}
else {
callback(cooldown);
}
}
});
}

_debugger.enable();
onNearlyScrolledToBottom(() => {
getNextPage();
}, { offset: 400 });
async function getNextPage() {
const anchorToNextPage = [...document.querySelectorAll("a.sb_pagN")].at(-1);
const response = await fetch(anchorToNextPage.href);
const contentOfNextPage = await response.text();
const elementForNextPage = document.createElement("div");
elementForNextPage.innerHTML = contentOfNextPage;
const resultList = elementForNextPage.querySelector("#b_results");
const relativeSearches = resultList.querySelector(".b_ans");
_debugger.log(relativeSearches);
resultList.removeChild(relativeSearches);
document.body.append(resultList);
}
97 changes: 0 additions & 97 deletions dist/playbackRateController_bundled.js

This file was deleted.

106 changes: 106 additions & 0 deletions dist/playbackRateController_bundled.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ==UserScript==
// @name Playback rate controller
// @version 0.0.2
// @match https://www.bilibili.com/video/*
// @match https://www.bilibili.com/bangumi/play/*
// @match https://www.bilibili.com/list/*
// @grant none
// @description
// ==/UserScript==
"use strict";
/**
* Promise-based `setTimeout`
*/
async function wait(time) {
function execute(resolve) {
setTimeout(resolve, time);
}
return new Promise(execute);
}

/**
* @param options.intervalOfRetry * Will retry at `a later time` if the element is null(e.g. not loaded in page yet)
* @warn This may cause an observer relying on the element to not work properly
* @default 1000
*/
async function selectElementAsync(selectors, options) {
const { intervalOfRetry = 1000, parent = document, expectingTheElementToExist = true, patient = false, } = { ...options };
let timesTried = 0;
while (true) {
if (expectingTheElementToExist && timesTried === 10) {
const prompt = `\`selectElementAsync\` for "${selectors}" failed ${timesTried} times`;
if (patient) {
console.info(prompt);
}
else {
console.warn(prompt);
}
}
timesTried += 1;
const element = parent.querySelector(selectors);
if (element === null) {
await wait(intervalOfRetry);
}
else {
return element;
}
}
}

const videoElement = await selectElementAsync(".bpx-player-video-wrap video");
const video = {
get playbackRate() {
return videoElement.playbackRate;
},
set playbackRate(rate) {
videoElement.playbackRate = rate;
},
togglePlayBackRate(rate1, rate2) {
videoElement.playbackRate = videoElement.playbackRate === rate1 ? rate2 : rate1;
},
basePlaybackRate: videoElement.playbackRate,
toggleBasePlayBackRate(rate1, rate2) {
this.basePlaybackRate = this.basePlaybackRate === rate1 ? rate2 : rate1;
},
};
enableTogglingPlaybackRate();
enableHoldingDownToControlPlaybackRate();
function enableTogglingPlaybackRate() {
const presetOfRates = [1, 2, 3, 4, 5, 6, 7, 8, 9];
window.addEventListener("keydown", (event) => {
if (presetOfRates.includes(Number(event.key))) {
video.togglePlayBackRate(Number(event.key), video.basePlaybackRate);
return;
}
switch (event.key) {
case "s": {
video.toggleBasePlayBackRate(1, 2);
break;
}
default:
return;
}
}, true);
}
function enableHoldingDownToControlPlaybackRate() {
window.addEventListener("keydown", (event) => {
switch (event.key) {
case "a": {
video.playbackRate = 4;
break;
}
default:
return;
}
}, true);
window.addEventListener("keyup", (event) => {
switch (event.key) {
case "a":
video.playbackRate = video.basePlaybackRate;
break;
default:
return;
}
}, true);
}
//
Loading

0 comments on commit 1a05cd5

Please sign in to comment.