Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shishirong committed Mar 18, 2023
0 parents commit 837a07b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
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
```
Binary file added image/1679125026864.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions scoop.sh_install_cmd_with_bucket_name.user.js
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);
};
}
})();

0 comments on commit 837a07b

Please sign in to comment.