Hide category_srl from short URL on document read page

This commit is contained in:
Kijin Sung 2024-05-09 02:26:15 +09:00
parent 1e30de7ce5
commit 74d651afdd

View file

@ -1,20 +1,28 @@
'use strict';
/**
* Remove comment_srl and unnecessary page number from short URL
* Remove unnecessary parameters from short URL.
*
* - category
* - comment_srl
* - page number
*/
(function() {
var newpath = '';
var match = location.pathname.match(/\/([a-zA-Z0-9_]+)\/([0-9]+)\/(comment|page)\/([0-9]+)$/);
if (match && match[1] === window.current_mid) {
var newpath = location.pathname.replace(/\/(comment|page)\/([0-9]+)$/, '');
if (location.hash && location.hash !== '#') {
newpath += location.hash;
}
if (history.replaceState) {
history.replaceState({
rx_replaced: true,
prev: location.pathname,
}, '', newpath);
}
newpath = location.pathname.replace(/\/(comment|page)\/([0-9]+)$/, '');
}
if (location.pathname.match(/\/([0-9]+)$/) && location.search.match(/^\?category=[0-9]+$/)) {
newpath = newpath ? newpath : location.pathname;
}
if (newpath && location.hash && location.hash != '#') {
newpath += location.hash;
}
if (newpath && history.replaceState) {
history.replaceState({
rx_replaced: true,
prev: location.pathname,
}, '', newpath);
}
})();