25 lines
750 B
JavaScript
25 lines
750 B
JavaScript
(function () {
|
|
function read() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
return {
|
|
path: params.get('path') || '',
|
|
play: params.get('play') || null
|
|
};
|
|
}
|
|
|
|
function write(path, play, replace) {
|
|
const url = new URL(window.location.href);
|
|
path ? url.searchParams.set('path', path) : url.searchParams.delete('path');
|
|
play ? url.searchParams.set('play', play) : url.searchParams.delete('play');
|
|
const next = `${url.pathname}${url.search}`;
|
|
window.history[replace ? 'replaceState' : 'pushState']({}, '', next);
|
|
}
|
|
|
|
function fileName(path) {
|
|
const parts = path.split('/');
|
|
return parts[parts.length - 1] || path;
|
|
}
|
|
|
|
window.LanPlayLocation = { read, write, fileName };
|
|
})();
|