Clone Turning Page Button in nicovideo

Also shows the pagination on the top of Nico Live search result, Lives by Category page, and Nico Video user page.

// ==UserScript==
// @name        Clone Turning Page Button in nicovideo
// @name:ja     niconico ページャーを上部にも表示
// @description Also shows the pagination on the top of Nico Live search result, Lives by Category page, and Nico Video user page.
// @description:ja ニコニコ生放送の検索結果、「放送中の番組」ページ、およびニコニコ動画のユーザーページにおいて、ページャー (ページ送りボタン) を上部にも表示します。
// @namespace   http://pc12.2ch.net/test/read.cgi/streaming/1275642556/
// @version     4.0.2
// @include     http://www.nicovideo.jp/user/*/video
// @include     http://www.nicovideo.jp/user/*/video/*
// @include     http://www.nicovideo.jp/user/*/video?*
// @include     http://www.nicovideo.jp/user/*/video#*
// @include     http://www.nicovideo.jp/user/*/stamp
// @include     http://www.nicovideo.jp/user/*/stamp/*
// @include     http://www.nicovideo.jp/user/*/stamp?*
// @include     http://www.nicovideo.jp/user/*/stamp#*
// @include     http://www.nicovideo.jp/my/video
// @include     http://www.nicovideo.jp/my/video/*
// @include     http://www.nicovideo.jp/my/video?*
// @include     http://www.nicovideo.jp/my/video#*
// @include     http://www.nicovideo.jp/my/stamp
// @include     http://www.nicovideo.jp/my/stamp/*
// @include     http://www.nicovideo.jp/my/stamp?*
// @include     http://www.nicovideo.jp/my/stamp#*
// @include     http://live.nicovideo.jp/search/*
// @include     http://live.nicovideo.jp/search?*
// @include     http://live.nicovideo.jp/recent
// @include     http://live.nicovideo.jp/recent/*
// @include     http://live.nicovideo.jp/recent?*
// @include     http://live.nicovideo.jp/recent#*
// @include     http://watch.live.nicovideo.jp/search/*
// @include     http://watch.live.nicovideo.jp/search?*
// @include     https://www.nicovideo.jp/user/*/video
// @include     https://www.nicovideo.jp/user/*/video/*
// @include     https://www.nicovideo.jp/user/*/video?*
// @include     https://www.nicovideo.jp/user/*/video#*
// @include     https://www.nicovideo.jp/user/*/stamp
// @include     https://www.nicovideo.jp/user/*/stamp/*
// @include     https://www.nicovideo.jp/user/*/stamp?*
// @include     https://www.nicovideo.jp/user/*/stamp#*
// @include     https://www.nicovideo.jp/my/video
// @include     https://www.nicovideo.jp/my/video/*
// @include     https://www.nicovideo.jp/my/video?*
// @include     https://www.nicovideo.jp/my/video#*
// @include     https://www.nicovideo.jp/my/stamp
// @include     https://www.nicovideo.jp/my/stamp/*
// @include     https://www.nicovideo.jp/my/stamp?*
// @include     https://www.nicovideo.jp/my/stamp#*
// @include     https://live.nicovideo.jp/search/*
// @include     https://live.nicovideo.jp/search?*
// @include     https://live.nicovideo.jp/recent
// @include     https://live.nicovideo.jp/recent/*
// @include     https://live.nicovideo.jp/recent?*
// @include     https://live.nicovideo.jp/recent#*
// @include     https://watch.live.nicovideo.jp/search/*
// @include     https://watch.live.nicovideo.jp/search?*
// @require     https://greasyfork.org/scripts/17895/code/polyfill.js?version=114170
// @require     https://greasyfork.org/scripts/17896/code/start-script.js?version=112958
// @license     Mozilla Public License Version 2.0 (MPL 2.0); https://www.mozilla.org/MPL/2.0/
// @compatible  Firefox
// @compatible  Opera
// @compatible  Chrome
// @grant       dummy
// @run-at      document-start
// @icon        data:image/vnd.microsoft.icon;base64,AAABAAEAMDAAAAEAIADMBwAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAwAAAAMAgGAAAAVwL5hwAAB5NJREFUaIHdWWtsHFcV/u6d2Zmd3Z21d9d2Y6+TtH4mKvUrdp6u5aaKooiqClUbHioESgUSf4qoqBAV0AqIAIk/4VEJUSSgpRIVtPyheQlQA4RGQJNiEeWFk9rUTt3C7sbenTs7M4cfu7Oe3ezDz9rlk6xZn3PvOd+555w7d+8CC8TQ4ABzP7fG41/d0t31Y/f/fffu5Qu1UwmDA/33t8bjx/t6e1vyIlZ1wlLw9ae+rDQ2NnyFMUaSJFF3d9dRV9fbc9eSHY4M7xnV9VACAAUCgT9v3dLVuSKES/HtI09HGxpiFwEQAJJlmbq7On+wHJt379m1NxwOp1ybgUCA+vt6D68E37I4sH9fTzQSGYcniK7OzmdcfVdX54IzMbx7576wrs+6tv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B0ZHhBNv8HQF4nZ+TFtAIAAAAASUVORK5CYII=
// @author      100の人
// @homepage    https://greasyfork.org/scripts/275
// ==/UserScript==

(function () {
'use strict';

if (location.pathname.startsWith('/search')) {
	// ニコニコ生放送 検索結果
	startScript(
		function () {
			let pager = document.getElementsByClassName('result-pager-area')[0];
			console.log(pager);
			if (pager) {
				// 41件以上ヒットしていれば
				// ページャーの複製
				document.getElementsByClassName('result-list')[0].before(pager.cloneNode(true));
			}
		},
		parent => parent.localName === 'main',
		target => target.classList.contains('search-result-context-area'),
		() => document.getElementsByClassName('search-result-context-area')[0]
	);
} else if (location.pathname.startsWith('/recent')) {
	// ニコニコ生放送 放送中の番組
	startScript(
		function () {
			clonePager();
			new MutationObserver(function (mutations) {
				if (mutations[0].addedNodes.length > 1) {
					// ページャーの複製でなければ
					clonePager();
				}
			}).observe(document.getElementById('onair_stream_list'), { childList: true });
			function clonePager() {
				document.getElementsByClassName('user-programs')[0].before(document.getElementById('pager-block').cloneNode(true));
			}
		},
		parent => parent.id === 'onair_stream_list',
		target => target.id === 'pager-block',
		() => document.getElementById('pager-block')
	);
} else if (/^\/(?:user\/[0-9]+|my)\/video(?:\/|\?|#|$)/.test(location.pathname)) {
	// ニコニコ動画 ユーザーページ 投稿動画
	startScript(
		function () {
			let pager = document.getElementsByClassName('pager')[0];
			if (pager) {
				document.head.insertAdjacentHTML('beforeend', `<style>
					.outer .pager {
						position: absolute;
						bottom: 0;
						right: 0;
					}
				</style>`);
				document.getElementsByClassName('outer')[0].append(pager.cloneNode(true));
			}
		},
		parent => parent.classList.contains('wrapper'),
		target => target.localName === 'script',
		() => document.querySelector('.wrapper > script')
	);
} else if (/^\/(?:user\/[0-9]+|my)\/stamp(?:\/|\?|#|$)/.test(location.pathname)) {
	// ニコニコ動画 ユーザーページ スタンプ帳
	document.addEventListener('load', function (event) {
		if (event.target.localName === 'script' && event.target.src.includes('jquery')) {
			let script = document.createElement('script');
			script.text = '(' + function () {
				jQuery.prototype.html = new Proxy(jQuery.prototype.html, {
					apply(target, thisArg, argumentsList) {
						var returnValue = target.apply(thisArg, argumentsList);
						if (thisArg.selector === '#stamp_list') {
							var pager = document.getElementsByClassName('pager')[0];
							if (pager) {
								thisArg[0].insertBefore(pager.parentElement.cloneNode(true), thisArg[0].firstChild);
							}
						}
						return returnValue;
					}
				});
			}.toString() + ')()';
			document.head.appendChild(script).remove();
		}
	}, true);
}

})();