Last active
February 16, 2019 02:50
-
-
Save mooz/0f60fa2d0b502f3d70b325f7cf4625b8 to your computer and use it in GitHub Desktop.
Scrapbox で履歴を表示 https://twitter.com/stillpedant/status/1096388563577462784
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (history) { | |
// 表示する履歴の数 | |
const maxHistory = 5; | |
if ($('#history-box').length) { return; } | |
const $header = $(".quick-launch"); | |
$header.append($(`<div class='flex-box'> | |
<div class='flex-item'> | |
<div class='left-box' id='history-box' /> | |
</div></div>`)); | |
const $historyHolder = $("#history-box"); | |
function pathToPageTitle(path) { | |
return decodeURIComponent(path.split("/")[2]); | |
} | |
let pushState = history.pushState; | |
history.pushState = function (state) { | |
try { | |
// on history change | |
var pageTitle = pathToPageTitle(state.path); | |
if (pageTitle) { | |
let $newHistory = $(`<span>→ <a href='${state.path}'>${pageTitle}</a></span>`); | |
$newHistory.on("click", () => { $newHistory.remove(); }); | |
$historyHolder.append($newHistory); | |
if ($historyHolder.children().length > maxHistory) { | |
$historyHolder.children().first().remove(); | |
} | |
} | |
} catch (x) { | |
console.error(x); | |
} | |
return pushState.apply(history, arguments); | |
}; | |
})(window.history); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#history-box span { | |
margin: 0 3px; | |
} | |
#history-box span:last-child { | |
font-weight: bold; | |
pointer-events: none; | |
cursor: default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment