|
// ==UserScript== |
|
// @name GROWIにクリップするやつ |
|
// @namespace https://mstdn.precure.fun/@karasu_sue |
|
// @version 1.3 |
|
// @description GROWIにクリップするやつ |
|
// @author Sue Karasugawa https://mstdn.precure.fun/@karasu_sue |
|
// @match https://mstdn.precure.fun/* |
|
// @match https://precure.ml/* |
|
// ==/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){ |
|
addGrowiTransferLink(status); |
|
} |
|
} |
|
}); |
|
}); |
|
|
|
function chromeClickChecker(event) { |
|
return( |
|
event.target.tagName.toLowerCase() === 'i' && |
|
event.target.classList.contains('fa-ellipsis-h') |
|
); |
|
} |
|
|
|
function firefoxClickChecker(event) { |
|
return( |
|
event.target.tagName.toLowerCase() === 'button' && |
|
event.target.classList.contains('icon-button') |
|
); |
|
} |
|
|
|
function addGrowiTransferLink(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('growi-clip'); |
|
var link = document.createElement('a'); |
|
link.setAttribute('href', '#'); |
|
link.setAttribute('target', '_blank'); |
|
link.setAttribute('ref', 'noopener'); |
|
link.setAttribute('role', 'button'); |
|
link.textContent = 'GROWIにクリッピング'; |
|
link.addEventListener('click', function(e) { |
|
e.preventDefault(); |
|
setTransferStatus(status); |
|
}); |
|
listItem.appendChild(link); |
|
dropdown.prepend(listItem); |
|
}, 100); |
|
} |
|
|
|
function setTransferStatus(status){ |
|
const growiclipping_command = 'command: growi_clipping\nurl: ' |
|
const statusLink = status.querySelector('.status__relative-time'); |
|
const 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, growiclipping_command + statusLink.getAttribute('href')); |
|
textarea.dispatchEvent(new Event('input', { bubbles: true })); |
|
|
|
// clipboad.setAttribute('type', 'hidden'); |
|
// clipboad.textContent = growiclipping_command + statusLink.getAttribute('href'); |
|
// 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(); |
|
} |
|
} |
|
})(); |