|
// ==UserScript== |
|
// @name QuoteTootするやつ |
|
// @namespace https://mstdn.precure.fun/@karasu_sue |
|
// @version 0.4 |
|
// @description QuoteTootするやつ |
|
// @author Sue Karasugawa https://mstdn.precure.fun/@karasu_sue |
|
// @match https://md.korako.me/* |
|
// ==/UserScript== |
|
(function() { |
|
'use strict'; |
|
window.addEventListener("load", function() { |
|
document.querySelector('body').addEventListener('click', function(event) { |
|
if (chromeClickChecker(event) || firefoxClickChecker(event)) { |
|
var status = event.target.parentNode.parentNode.parentNode.parentNode.parentNode |
|
if (status.querySelector('div.status__action-bar__dropdown') != null){ |
|
addQuotetootLink(status); |
|
} |
|
} |
|
}); |
|
}); |
|
|
|
function chromeClickChecker(event) { |
|
return( |
|
event.target.tagName.toLowerCase() === 'i' && |
|
event.target.classList.contains('fa-close') |
|
); |
|
} |
|
|
|
function firefoxClickChecker(event) { |
|
return( |
|
event.target.tagName.toLowerCase() === 'button' && |
|
event.target.classList.contains('icon-button') |
|
); |
|
} |
|
|
|
function addQuotetootLink(status){ |
|
setTimeout(function() { |
|
if((document.querySelector('div.dropdown-menu ul') != null)){ |
|
var dropdown = document.querySelector('div.dropdown-menu ul'); |
|
}else if(document.querySelector('.modal-root__modal ul') != null){ |
|
var dropdown = document.querySelector('.modal-root__modal ul'); |
|
}else{ |
|
return; |
|
} |
|
var listItem = document.createElement('li'); |
|
listItem.classList.add('dropdown-menu__item'); |
|
listItem.classList.add('quotetoot'); |
|
var link = document.createElement('a'); |
|
link.setAttribute('href', '#'); |
|
link.setAttribute('target', '_blank'); |
|
link.setAttribute('ref', 'noopener'); |
|
link.setAttribute('role', 'button'); |
|
link.textContent = '引用する'; |
|
link.addEventListener('click', function(e) { |
|
e.preventDefault(); |
|
setTransferStatus(status); |
|
}); |
|
listItem.appendChild(link); |
|
dropdown.prepend(listItem); |
|
}, 100); |
|
} |
|
|
|
function setTransferStatus(status){ |
|
const statusLink = status.querySelector('.status__relative-time'); |
|
const newstatusText = '\r\rQT:[' + statusLink.getAttribute('href') + ']'; |
|
var clipboad = document.createElement('textarea'); |
|
const drawer = document.querySelector('.drawer'); |
|
const textarea = drawer.querySelector('.autosuggest-textarea__textarea'); |
|
Object.getOwnPropertyDescriptor(Object.getPrototypeOf(textarea), 'value').set |
|
.call(textarea, newstatusText); |
|
textarea.dispatchEvent(new Event('input', { bubbles: true })); |
|
|
|
clipboad.setAttribute('type', 'hidden'); |
|
clipboad.textContent = newstatusText |
|
document.body.appendChild(clipboad); |
|
clipboad.select(); |
|
document.execCommand("copy"); |
|
document.body.removeChild(clipboad); |
|
try{ |
|
document.querySelector('.dropdown-menu ul').remove(); |
|
} catch(e){} |
|
if(document.querySelector('.autosuggest-textarea__textarea') != null){ |
|
document.querySelector('.autosuggest-textarea__textarea').focus(); |
|
} |
|
} |
|
})(); |