Skip to content

Instantly share code, notes, and snippets.

@karasugawasu
Created April 2, 2020 16:23
Show Gist options
  • Save karasugawasu/eb0cf2cce71bd113d4cc7a05607fc3a6 to your computer and use it in GitHub Desktop.
Save karasugawasu/eb0cf2cce71bd113d4cc7a05607fc3a6 to your computer and use it in GitHub Desktop.
タグ固定するやつ(misskey)
// ==UserScript==
// @name タグ固定するやつ(Misskey)
// @namespace https://mstdn.precure.fun/@karasu_sue
// @version 1.0.0β
// @description タグ固定するやつ(Misskey)
// @author Sue Karasugawa https://mstdn.precure.fun/@karasu_sue
// @match https://misskey.xn--krsgw--n73t.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
var koteitag_list_index = 0;
var template_list;
window.addEventListener("load", function() {
document.querySelector('body').addEventListener('click', function(event) {
if (chromeClickChecker(event)) {
Init();
}
});
});
function Init(){
var css = `
._button[krsgw_us] {
display: inline-block;
padding: 0;
margin: 0;
font-size: 16px;
width: 48px;
height: 48px;
border-radius: 6px;
}
._button[krsgw_us].active {
color: var(--accent);
}
.koteitag-input[krsgw_us] {
display: block;
box-sizing: border-box;
padding: 0 24px;
margin: 0;
width: 100%;
font-size: 16px;
border: none;
border-radius: 0;
background: transparent;
color: var(--fg);
font-family: inherit;
z-index: 1;
padding-bottom: 8px;
border-bottom: 1px solid var(--divider);
}`;
GM_addStyle(css)
addKoteitagButton();
addKoteitagInput();
}
function chromeClickChecker(event) {
return(
event.target.className == 'post _buttonPrimary'
);
}
function addKoteitagInput(){
var koteitag = document.createElement('input');
koteitag.classList.add('koteitag-input');
koteitag.setAttribute('krsgw_us','');
koteitag.setAttribute('placeholder','固定するタグをカンマ区切りで書いてください');
koteitag.style.display = 'none';
koteitag.addEventListener('keydown', setTagsCommand, true);
document.querySelector('.gafaadew>.form>.mk-uploader').appendChild(koteitag);
}
function addKoteitagButton(){
var koteibutton = document.createElement('button');
koteibutton.classList.add('_button');
koteibutton.setAttribute('krsgw_us','');
koteibutton.setAttribute('title', '固定タグが設定されていません');
koteibutton.setAttribute('aria-controls', 'koteitag-input');
koteibutton.addEventListener('click', clicktagbutton);
var buttontext = document.createElement('p');
buttontext.classList.add('krsgw_us');
buttontext.appendChild(document.createTextNode('#'));
koteibutton.appendChild(buttontext);
document.querySelector('.gafaadew>.form>footer').appendChild(koteibutton);
}
function setEvents(){
document.querySelector('.gafaadew>header>div>.submit').addEventListener('click', setkoteitag);
document.querySelector('.gafaadew>.form>.text').addEventListener('keydown', pressed_keyconfirm);
}
function pressed_keyconfirm() {
if(event.ctrlKey){
if(event.keyCode === 13){
return true;
}
}
}
function setTagsCommand() {
if (pressed_keyconfirm()) {
var command = 'command: user_config\ntags:';
var taglist = document.querySelector('.koteitag-input[krsgw_us]').value.split(',');
if (taglist[0] == ''){
command = command + ' null';
}else{
for (var tag of taglist) {
command = command + '\n- ' + tag;
}
}
setTextAreaText(command);
}
}
function setTextAreaText(value){
const textarea = document.querySelector('.gafaadew>.form>.text');
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(textarea), 'value').set
.call(textarea, value);
textarea.dispatchEvent(new Event('input', { bubbles: true }));
}
function clicktagbutton(){
if (document.querySelector('._button[krsgw_us]').getAttribute('title') == "固定タグが設定されていません") {
document.querySelector('._button[krsgw_us]').setAttribute('title','固定タグが設定されています');
document.querySelector('._button[krsgw_us]').classList.add('active');
document.querySelector('.koteitag-input[krsgw_us]').style.display = '';
} else {
document.querySelector('._button[krsgw_us]').setAttribute('title','固定タグが設定されていません');
document.querySelector('._button[krsgw_us]').classList.remove('active');
document.querySelector('.koteitag-input[krsgw_us]').style.display = 'none';
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment