- Tampermonkeyを入れる Chrome, Firefox, Microsoft Edge, Safari
- これをクリック→https://gist.github.com/Petitsurume/f7256fb115177bee73bead14d6a46f70/raw/nicommentpost.user.js
- https://friends.nico/nicomment を開く
- やったぜ。
これはWTFPLです。
これはWTFPLです。
// ==UserScript== | |
// @name NicommentPost | |
// @namespace https://surume.tk | |
// @version 0.1 | |
// @description Nicommentにコメント投稿欄の追加 | |
// @author You | |
// @match https://friends.nico/nicomment | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
// Your code here... | |
var nowPosting = false | |
var nowAjax = true | |
var accessToken = "" | |
var css = document.createElement("style") | |
css.innerText = ".app{height:calc(100% - 2em);}" | |
document.body.appendChild(css) | |
var comment_form = document.createElement("form") | |
comment_form.style.position="fixed" | |
comment_form.style.bottom="0" | |
comment_form.style.left = "10vw" | |
comment_form.style.right = "10vw" | |
comment_form.style.height="2em" | |
comment_form.style.display="flex" | |
comment_form.action = "javascript://" | |
var comment_input = document.createElement("input") | |
comment_input.disabled = true | |
comment_input.type="text" | |
comment_input.style.flex="8" | |
comment_input.placeholder="コメントを入力" | |
comment_input.onsubmit = alert | |
comment_form.appendChild(comment_input) | |
var comment_post_button = document.createElement("button") | |
comment_post_button.disabled = true | |
comment_post_button.style.backgroundColor = "orange" | |
comment_post_button.innerText = "コメント" | |
comment_post_button.style.flex="2" | |
comment_post_button.type="submit" | |
comment_form.onsubmit = function(){ | |
if(nowPosting || nowAjax) return | |
nowPosting = true | |
comment_post_button.disabled = true | |
comment_post_button.innerText = "コメント中..." | |
comment_input.disabled = true | |
fetch("/api/v1/statuses",{ | |
headers: {"Authorization": "bearer "+accessToken, "Content-Type": "application/json"}, | |
method: 'POST', | |
body: JSON.stringify({"status":comment_input.value,"in_reply_to_id":null,"media_ids":[],"sensitive":false,"spoiler_text":"","visibility":"public"}) | |
}).then(res => { | |
return res.json() | |
}).then(json => { | |
comment_input.value = "" | |
comment_input.disabled = false | |
comment_post_button.disabled = false | |
nowPosting = false | |
comment_post_button.innerText = "コメント" | |
}) | |
} | |
comment_form.appendChild(comment_post_button) | |
document.body.appendChild(comment_form) | |
fetch("/web/getting-started", {credentials: 'include'}).then(res => { | |
return res.text() | |
}).then(res => { | |
var dom = (new DOMParser()).parseFromString(res, "text/html") | |
if(dom.getElementsByTagName("parsererror").length) return // パースエラー | |
var infoJSON = JSON.parse(dom.getElementById("initial-state").innerText) | |
console.log(infoJSON) | |
accessToken = infoJSON.meta.access_token | |
comment_input.disabled = false | |
comment_post_button.disabled = false | |
nowAjax = false | |
setTimeout(function(){comment_input.focus()},1) | |
}) | |
})(); |