2021-09-08 19:26:08 +08:00
|
|
|
|
2021-09-05 06:36:48 +08:00
|
|
|
const TITLE_WITH_VIEW = 3;
|
|
|
|
|
|
|
|
const getTitleData = () => {
|
|
|
|
const title = document.getElementsByTagName('title')[0];
|
|
|
|
return { title, data: title?.text?.split(' - ') };
|
|
|
|
}
|
|
|
|
|
|
|
|
export const registerTitleView = (v) => {
|
|
|
|
const { title, data } = getTitleData();
|
|
|
|
if (data.length < TITLE_WITH_VIEW) data.push(`${v}`);
|
|
|
|
else data.splice(TITLE_WITH_VIEW - 1, TITLE_WITH_VIEW, v);
|
|
|
|
title.text = data.join(' - ');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const unregisterTitleView = () => {
|
|
|
|
const { title, data } = getTitleData();
|
|
|
|
if (data.length === TITLE_WITH_VIEW) {
|
|
|
|
data.splice(TITLE_WITH_VIEW - 1, TITLE_WITH_VIEW, 'Default');
|
|
|
|
}
|
|
|
|
title.text = data.join(' - ');
|
|
|
|
};
|
|
|
|
|
2022-07-26 03:53:19 +08:00
|
|
|
export const convertRemToPixels = (rem) => {
|
|
|
|
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
|
|
|
|
}
|
|
|
|
|
2022-05-24 01:09:50 +08:00
|
|
|
export default {
|
|
|
|
registerTitleView,
|
|
|
|
unregisterTitleView,
|
2022-07-26 03:53:19 +08:00
|
|
|
convertRemToPixels,
|
2022-01-24 00:18:09 +08:00
|
|
|
};
|