Skip to content

Instantly share code, notes, and snippets.

@jeffrey4l
Last active October 24, 2022 01:52
Show Gist options
  • Select an option

  • Save jeffrey4l/aa9cdae0453cdfd0891c06e6f0303c40 to your computer and use it in GitHub Desktop.

Select an option

Save jeffrey4l/aa9cdae0453cdfd0891c06e6f0303c40 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Jeffrey4l Enhance
// @namespace https://gist.github.com/jeffrey4l/aa9cdae0453cdfd0891c06e6f0303c40
// @version 0.5
// @description try to take over the world!
// @author Jeffrey4l
// @match *://baidu.com/*
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// ==/UserScript==
var _Enhance = {
title: undefined,
mappings: {},
fullTitle(){
var titleElement = document.getElementsByTagName('title')[0]
this.title = titleElement.text
if (titleElement === undefined){
return
}
var host = window.location.host
if (this.mappings[host] === undefined ){
titleElement.text += " - " + host
} else {
titleElement.text += " - " + this.mappings[host]
}
},
getPageInfo(md = false) {
let url = document.location.href;
var t = this.title
if (md){
t = t.replace(/([_\[\]\|])/g, "");
}
return [this.title, url];
},
registerMenu(){
GM_registerMenuCommand("Copy as Plain", () => {
const [title, url] = this.getPageInfo();
GM_setClipboard(`${title}\n${url}\n`);
});
GM_registerMenuCommand("Copy as Markdown", () => {
const [title, url] = this.getPageInfo(true);
GM_setClipboard(`[${title}](${url})\n`);
});
GM_registerMenuCommand("Copy as TiddlyWiki", () => {
const [title, url] = this.getPageInfo(true);
GM_setClipboard(`[[${title}|${url}]]\n`);
});
GM_registerMenuCommand("Copy as TiddlyWiki List", () => {
const [title, url] = this.getPageInfo(true);
GM_setClipboard(`* [[${title}|${url}]]\n`);
});
},
init(){
this.fullTitle()
this.registerMenu()
}
};
(function() {
'use strict';
if (window.frames.length != parent.frames.length) {
return false;
}
_Enhance.init()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment