【油猴脚本】学习笔记

Tampermonkey v4.19.0


  原教程:手写油猴脚本,几分钟学会新技能——王子周棋洛
  Tampermonkey首页
  面向 Web 开发者的文档
  Greasy Fork

新建用户脚本

打开【管理面板】
在这里插入图片描述
点击【+】,即可新建一个用户脚本
在这里插入图片描述
在这里插入图片描述

模板

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.bilibili.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
})();

源注释

用于被油猴插件读取,

// ==UserScript==
// @name         New Userscript					脚本名
// @namespace    http://tampermonkey.net/		无用
// @version      0.1							版本号
// @description  try to take over the world!	描述
// @author       You							作者
// @match        https://www.bilibili.com/		匹配原则,脚本要在哪些网页生效
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com	脚本图标
// @grant        none
// ==/UserScript==

测试代码

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://blog.csdn.net/*/article/details/*
// @icon         https://g.csdnimg.cn/static/logo/favicon32.ico
// @grant        none
// ==/UserScript==

//获取所有代码块
let codes = document.querySelectorAll("code");
//循环遍历所有代码块
codes.forEach(c => {
//设置代码块可以编辑,从而实现可复制
c.contentEditable = "true";
});

获取图标

F12后在【网络】搜索".ico"刷新网页,即可获取到相应的对象:
在这里插入图片描述
选择标头,可见其URL为 https://g.csdnimg.cn/static/logo/favicon32.ico
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

乙酸氧铍

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值