利用者:1108-Kiju/escape.js

出典: 謎の百科事典もどき『エンペディア(Enpedia)』
ナビゲーションに移動 検索に移動

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer / Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: Ctrl-F5を押してください
const styles=`
.container {
  border: 1px solid #ccc;
  padding: 10px;
  background-color: #f9f9f9;
  border-radius: 5px;
}

.button {
  display: block;
  width: 100%;
  color: white;
  background-color: #d4dcda;
  border: none;
  padding: 8px;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  margin: 5px 0;
  border-radius: 5px;
  cursor: pointer;
}

.button:hover {
  background-color: #0056b3;
}

.hidden {
  display: none;
}

.note {
  color: red;
  font-size: 15px;
}
`;$(function(){$("head").append("<style>"+styles+"</style>");var currentUrl=window.location.href;if(!currentUrl.includes("action=history")){return}var containerDiv=document.createElement("div");containerDiv.classList.add("container");var buttonShow=document.createElement("button");buttonShow.textContent="移入元情報を表示";buttonShow.classList.add("button");var buttonHide=document.createElement("button");buttonHide.textContent="閉じる";buttonHide.classList.add("button","hidden");var contentDiv=document.createElement("div");contentDiv.classList.add("content","hidden");var latestTimestamp=$(".mw-changeslist-date").first().text().trim();var pageTitle=encodeURIComponent(mw.config.get("wgPageName"));var userSet=new Set;$(".mw-userlink").each(function(){userSet.add($(this).text().trim())});var userList=Array.from(userSet).join("、");var element=document.querySelector(".mw-pager-navigation-bar");if(element){var noteDiv=document.createElement("div");noteDiv.textContent="warning:ページ上に全ての版を表示しているか確認してください";noteDiv.classList.add("note");containerDiv.appendChild(noteDiv);var showAllRevisionsButton=document.createElement("button");showAllRevisionsButton.textContent="ページの全版を表示する";showAllRevisionsButton.classList.add("button");showAllRevisionsButton.addEventListener("click",function(){var rawUrl="https://ja.wikipedia.org/w/index.php?title="+pageTitle+"&action=history&limit=5000";window.location.href=rawUrl});containerDiv.appendChild(showAllRevisionsButton);var hr=document.createElement("hr");containerDiv.appendChild(hr)}var escapeCopyButton=document.createElement("button");escapeCopyButton.textContent="この記事をエスケープ転載";escapeCopyButton.classList.add("button");escapeCopyButton.addEventListener("click",function(){var url="https://enpedia.rxy.jp/w/index.php?title="+pageTitle+"&action=edit&summary=[[jawp:"+pageTitle+"]]の"+latestTimestamp+"の版よりエスケープ転載。投稿者: "+userList+"。";window.open(url,"_blank")});containerDiv.appendChild(escapeCopyButton);var showRawButton=document.createElement("button");showRawButton.textContent="この記事のソースを表示";showRawButton.classList.add("button");showRawButton.addEventListener("click",function(){var rawUrl="https://ja.wikipedia.org/w/index.php?title="+pageTitle+"&action=raw";window.open(rawUrl,"_blank")});containerDiv.appendChild(showRawButton);var resultDiv=document.createElement("div");resultDiv.innerHTML="以下、移入元情報を記載する。<br><br>"+"この記事は [[jawp:"+pageTitle+"]] の"+latestTimestamp+"時点の版から転記された。<br><br>"+"投稿者: "+userList+"(敬称略)<br><br>"+"改変点: 無し<br><br>"+"追記: 無し<br><br>"+"以上。";contentDiv.appendChild(resultDiv);buttonShow.addEventListener("click",showContent);buttonHide.addEventListener("click",hideContent);function showContent(){contentDiv.classList.remove("hidden");buttonShow.classList.add("hidden");buttonHide.classList.remove("hidden");buttonShow.textContent="移入元情報を非表示"}function hideContent(){contentDiv.classList.add("hidden");buttonShow.classList.remove("hidden");buttonHide.classList.add("hidden");buttonShow.textContent="移入元情報を表示"}containerDiv.appendChild(buttonShow);containerDiv.appendChild(buttonHide);containerDiv.appendChild(contentDiv);function selectText(element){var range=document.createRange();range.selectNodeContents(element);var selection=window.getSelection();selection.removeAllRanges();selection.addRange(range)}document.addEventListener("keydown",function(event){if(event.ctrlKey&&event.key==="a"){event.preventDefault();selectText(contentDiv)}});var subtitleElement=document.querySelector("#mw-content-subtitle");subtitleElement.appendChild(containerDiv)});function getFormattedDate(timestamp){if(timestamp>0){var latestDate=new Date(timestamp);var year=latestDate.getUTCFullYear();var month=("0"+(latestDate.getUTCMonth()+1)).slice(-2);var day=("0"+latestDate.getUTCDate()).slice(-2);var hours=("0"+latestDate.getUTCHours()).slice(-2);var minutes=("0"+latestDate.getUTCMinutes()).slice(-2);var seconds=("0"+latestDate.getUTCSeconds()).slice(-2);return year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+" (UTC)"}else{return""}}