Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature: Content outdated notice #136

Open
urain39 opened this issue Mar 11, 2020 · 2 comments
Open

New Feature: Content outdated notice #136

urain39 opened this issue Mar 11, 2020 · 2 comments

Comments

@urain39
Copy link
Contributor

urain39 commented Mar 11, 2020

(function() {
	var date = new Date();
	var pathname = self.location.pathname;
	var postYear = parseInt(pathname.slice(1, 5));
	var postMonth = parseInt(pathname.slice(6, 8));
	if ((date.getFullYear() - postYear) * 12 +
		(date.getMonth() + 1 - postMonth) < 6)
		return; // 小于6个月,非过时内容
	var notice = document.createElement('div');
	notice.style['top'] = '0';
	notice.style['left'] = '0';
	notice.style['width'] = '100%';
	notice.style['text-align'] = 'center';
	notice.style['background'] = '#ffee00';
	var language = (navigator.browserLanguage || navigator.language).toLowerCase();
	if (language === 'zh-cn')
		notice.innerHTML = '<h2>注意:页面内容可能过时或不正确,请谨慎参考!</h2>';
	else
		notice.innerHTML = '<h3>Note: The page content may be outdated or incorrect, please use caution!</h3>';
	var firstChild = document.body.firstChild;
	document.body.insertBefore(notice, firstChild);
	setTimeout(function () {
		notice.style['display'] = 'none';
	}, 1000 * 10);
})();
@urain39
Copy link
Contributor Author

urain39 commented Mar 11, 2020

以前在某些博客里看到过类似的实现,然后自己试着自己实现了一个,仅供参考。

@urain39
Copy link
Contributor Author

urain39 commented Mar 11, 2020

效果如图所示:
S00311-17120120.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant