This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 837a07b
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# readme | ||
|
||
在[scoop.sh](scoop.sh)上搜索和复制命令来安装软件非常方便,唯一不足的是想要安装指定bucket的软件需要手动输入bucket名称,所以用这个脚本来增加一个按钮,让复制 `install` 命令时更方便。 | ||
|
||
效果如下: | ||
|
||
![1679125026864](image/1679125026864.png) | ||
|
||
* 左边按钮复制的内容: | ||
|
||
```powershell | ||
scoop install sudo | ||
``` | ||
|
||
* 右边按钮复制的内容: | ||
|
||
```powershell | ||
scoop install main/sudo | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// ==UserScript== | ||
// @name scoop.sh install cmd with bucket name | ||
// @namespace http://tampermonkey.net/ | ||
// @version 0.1 | ||
// @description scoop.sh install cmd with bucket name (让scoop.sh增加一个按钮使得复制命令时可以附带上bucket名,如:scoop install sudo -> scoop install main/sudo) | ||
// @author stoneman | ||
// @match *://scoop.sh/* | ||
// @icon https://scoop.sh/favicon.ico | ||
// @grant none | ||
// @run-at document-idle | ||
// @license BSD | ||
// ==/UserScript== | ||
|
||
(function () { | ||
'use strict'; | ||
|
||
var added_el = []; | ||
let observer = new MutationObserver(observer_action); | ||
observer.observe(document, { childList: true, subtree: true }); | ||
|
||
function observer_action(observer) { | ||
let cards = document.querySelectorAll("div.card-body") | ||
for (const element of cards) { | ||
if (added_el.includes(element)) { | ||
continue; | ||
} | ||
added_el.push(element); | ||
|
||
let bucket_name = element.querySelector("div#bucket-command input").value.split(' ')[3]; | ||
let cmd = element.querySelector("div#app-command input").value; | ||
let cmd_new = cmd.slice(0, 14) + `${bucket_name}/` + cmd.slice(14); | ||
|
||
let el_bt = element.querySelector("div#app-command button"); | ||
let el = document.createElement("button"); | ||
el.value = cmd_new; | ||
el.type = 'button'; | ||
el.title = '复制含bucket名的命令'; | ||
el.className = el_bt.className; | ||
for (const cel of el_bt.children) { | ||
el.append(cel.cloneNode(true)); | ||
}; | ||
el.addEventListener('click', async (e) => { | ||
// observer.disconnect(); | ||
el.disabled = true; | ||
element.querySelector("div#app-command input").value = el.value; | ||
await navigator.clipboard.writeText(el.value) | ||
setTimeout(() => { | ||
el.disabled = false; | ||
}, 1000); | ||
}); | ||
el_bt.parentElement.appendChild(el); | ||
//console.log(cmd_new); | ||
}; | ||
} | ||
})(); |