Skip to content

Instantly share code, notes, and snippets.

@defaultcf
Created August 14, 2022 10:22
Show Gist options
  • Save defaultcf/a21687d260346a3bece07d113bf2db47 to your computer and use it in GitHub Desktop.
Save defaultcf/a21687d260346a3bece07d113bf2db47 to your computer and use it in GitHub Desktop.
vket more useful
// ==UserScript==
// @name vket more useful
// @namespace Violentmonkey Scripts
// @match https://summer2022.vket.com/circle/*
// @grant none
// @version 1.0
// @author i544c
// @description vketの説明文中のリンクを開きやすくしたりする
// ==/UserScript==
class Main {
constructor() {
this.description_path = ".detail-description"
this.re_url = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/g
}
wait(ms) {
return new Promise(r => setTimeout(r, ms))
}
create_a(url) {
const a = document.createElement('a')
const content = document.createTextNode(url)
a.setAttribute('href', url)
a.appendChild(content)
return a.outerHTML
}
async run() {
await this.wait(300) // Nuxtによるレンダリングが終わるのを待つ
const description_area = document.querySelector(this.description_path)
const description = description_area?.innerHTML ?? ''
const replaced = description.replaceAll(this.re_url, this.create_a)
description_area.innerHTML = replaced
}
}
const main = new Main()
main.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment