Skip to content

Instantly share code, notes, and snippets.

@am4dr
Last active January 1, 2020 18:05
Show Gist options
  • Save am4dr/e403980f0c6788d7979a537923afb1d8 to your computer and use it in GitHub Desktop.
Save am4dr/e403980f0c6788d7979a537923afb1d8 to your computer and use it in GitHub Desktop.
ユーザースクリプト置き場
// ==UserScript==
// @name <title>
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.0.1
// @description <description>
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/<name>.user.js
// @match <url *://*>
// @grant none
// ==/UserScript==
(function() {
'use strict';
})();
// ==UserScript==
// @name dアニメストア - 各アニメページ - 表示話数変更
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1
// @description 各アニメのページで一度に表示される話数を変更する。(14でだいたい1ページあるいは2ページに収めたい)
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/dAnimeStore_animepage_num-of-stories.user.js
// @match https://anime.dmkt-sp.jp/animestore/ci_pc*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const slideSelector = '.episodeContainer.itemWrapper.swiper-wrapper > .swiper-slide';
const slides = Array.from(document.querySelectorAll(slideSelector));
const items = slides.reduce((acc, node) => acc.concat(...node.querySelectorAll('.itemModule.list')), []);
const count = 14;
for (var i = 0; i*count < items.length; ++i) {
items.slice(i*count, (i+1)*count).forEach((it) => slides[i].appendChild(it));
}
})();
// ==UserScript==
// @name dアニメストア - 次の1話 - 更新曜日表示
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1.3
// @description 次の1話のページで更新曜日を推測して表示する。更新日、更新曜日、配信期間ありに'update-date', ('update-day-*', 'until-update-day-*'), 'has-deadline'をつける。
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/dAnimeStore_next_update-day.user.js
// @match https://anime.dmkt-sp.jp/animestore/mp_viw_pc*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const currentDate = new Date();
const daysString = ["日", "月", "火", "水", "木", "金", "土"];
const tagList = document.querySelectorAll(".itemModule.list ul.option");
const dateReg = /(\d+)\/(\d+) 話追加/;
function getDate(str) {
const date = dateReg.exec(str);
return date ? date.slice(1,3) : date;
}
function getUpdateDateTag(tagList) {
const tags = Array.from(tagList.getElementsByTagName('li'));
const updateDateTag = tags.find(tag => tag.textContent && getDate(tag.textContent));
if (!updateDateTag) return updateDateTag;
else return {
'tag': updateDateTag,
'date': getDate(updateDateTag.textContent)
};
}
function calcUpdateDay(month, day) {
var addedYear = currentDate.getFullYear();
if (month > currentDate.getMonth() + 1) {
--addedYear;
}
const addedDate = new Date(addedYear, month - 1, day);
return addedDate.getDay();
}
tagList.forEach(tag => {
const updateDateTag = getUpdateDateTag(tag);
if (updateDateTag) {
updateDateTag.tag.classList.add('updated-date');
const updateDay = calcUpdateDay(...updateDateTag.date);
const diffDay = (updateDay - currentDate.getDay() + 7) % 7;
const dayTag = document.createElement('li');
dayTag.classList.add(`update-day-${updateDay}`, `until-update-day-${diffDay}`);
dayTag.textContent = daysString[updateDay];
tag.insertBefore(dayTag, updateDateTag.tag);
}
for (var li of tag.getElementsByTagName('li')) {
if (li && li.textContent === '配信期間あり') {
li.classList.add('has-deadline');
}
}
});
})();
// ==UserScript==
// @name 小説家になろう - ブクマ - 完結済みかを目印
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1.2
// @description ブックマークページにて完結済みならcompletedをさもなくばnot-completedをfavnovelに対して付与する
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/syosetu_bookmarks_complete-state.user.js
// @match *://syosetu.com/favnovelmain*/list/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const novels = document.getElementsByClassName('favnovel');
for (const novel of novels) {
const no = novel.getElementsByClassName('no');
if (no.length === 0) { continue; }
const content = no[0].textContent;
if (content.includes('最終')) {
novel.classList.add('completed');
}
else {
novel.classList.add('not-completed');
}
}
})();
// ==UserScript==
// @name 小説家になろう - ブクマ - 最終更新日を目印
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1.2
// @description ブックマークページにて最終更新が1年前ならlast-update-12m、半年前ならlast-update-6mをfavnovelに対して付与する
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/syosetu_bookmarks_last-update.user.js
// @match *://syosetu.com/favnovelmain*/list/*
// @grant none
// ==/UserScript==
/* 判定の粗さは日くらい */
(function() {
'use strict';
/* テキスト例: 更新日:2017/05/25 23:28 */
const reg = /更新日:(\d+)\/(\d+)\/(\d+)/;
function getDate(str) {
const date = reg.exec(str);
if (!date) { return date; }
return Date.UTC(date[1], date[2] - 1, date[3]);
}
const now_millis = Date.now();
const month_millis = 60 * 60 * 24 * 30 * 1000;
const novels = document.getElementsByClassName('favnovel');
for (const novel of novels) {
const info = novel.getElementsByClassName('info');
if (info.length === 0) { continue; }
const content = info[0].getElementsByTagName('p')[0].textContent;
const date = getDate(content);
if (!date) { continue; }
const elapse = now_millis - date;
if (elapse >= 12*month_millis) {
novel.classList.add('last-update-12m');
}
else if (elapse >= 6*month_millis) {
novel.classList.add('last-update-6m');
}
else if (elapse <= month_millis) {
novel.classList.add('last-update-1m');
}
}
})();
// ==UserScript==
// @name 小説家になろう - ブクマ - 更新の有無を目印
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1.3
// @description ブックマークページにて更新があれば.has-updateを、なければno-updateを、未読のものにはnew-novelをfavnovelに対して付与する
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/syosetu_bookmarks_update-state.user.js
// @match *://syosetu.com/favnovelmain*/list/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const novels = document.getElementsByClassName('favnovel');
for (const novel of novels) {
const no = novel.getElementsByClassName('no');
if (no.length === 0) { continue; }
const aTags = no[0].getElementsByTagName('a');
if (!aTags || aTags.length === 0) {
continue;
}
else if (aTags.length === 1) {
novel.classList.add('new-novel');
}
else if (aTags.length === 2) {
if (aTags[0].href !== aTags[1].href) {
novel.classList.add('has-update');
}
else {
novel.classList.add('no-update');
}
}
}
})();
// ==UserScript==
// @name Twitter - add self-retweet class
// @namespace https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8
// @version 0.1.2
// @description add `self-retweet` class to self-retweeted tweets
// @author am4dr
// @updateURL https://gist.github.com/am4dr/e403980f0c6788d7979a537923afb1d8/raw/twitter_self-retweet_class.user.js
// @match *://twitter.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function() {
'use strict';
function addSelfRetweetClassIfItIs(streamItem) {
if (!streamItem) { return; }
const tweet = streamItem.getElementsByClassName('tweet')[0];
if (tweet.dataset.screenName === tweet.dataset.retweeter) {
tweet.classList.add('self-retweet');
}
}
const streamOl = document.getElementById('stream-items-id');
const tweets = streamOl.getElementsByClassName('stream-item');
for (const tweet of tweets) { addSelfRetweetClassIfItIs(tweet); }
const obs = new MutationObserver(records =>
records.forEach(r => r.addedNodes.forEach(addSelfRetweetClassIfItIs))
);
obs.observe(streamOl, {childList: true});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment