-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,3 @@ | ||
'use strict'; | ||
|
||
hexo.extend.filter.register('after_render:html', function (html) { | ||
const config = hexo.config; | ||
if (!config.memorial_day.enable) { | ||
return; | ||
} | ||
|
||
if (html.search('<html') === -1 || html.search('grayscale(100%)') > -1) { | ||
return; | ||
} | ||
|
||
const css = 'html { \ | ||
-webkit-filter: grayscale(100%); /* webkit */ \ | ||
-moz-filter: grayscale(100%); /* firefox */ \ | ||
-ms-filter: grayscale(100%); /* ie9 */ \ | ||
-o-filter: grayscale(100%); /* opera */ \ | ||
filter: grayscale(100%); \ | ||
filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); filter:gray; /* ie9- */ \ | ||
}'; | ||
|
||
const js = ` | ||
<script type="text/javascript"> | ||
(function() { | ||
var now = new Date(); | ||
var dayStr = '${ config.memorial_day.day }'; | ||
var day = dayStr ? new Date(dayStr) : new Date(); | ||
var isMemorialDay = now.getFullYear() === day.getFullYear() && now.getMonth() === day.getMonth() && now.getDay() === day.getDay(); | ||
if (isMemorialDay) { | ||
if (document.all) { | ||
window.style = '${ css }'; | ||
document.createStyleSheet('javascript:style'); | ||
} else { | ||
var style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
style.innerHTML = '${ css }'; | ||
document.getElementsByTagName('HEAD').item(0).appendChild(style); | ||
} | ||
} | ||
})(); | ||
</script> | ||
`; | ||
|
||
return js + html; | ||
}); | ||
hexo.extend.filter.register('after_render:html', require('./lib/filter')); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module.exports = function (html, data) { | ||
const config = this.config; | ||
|
||
if (!config.memorial_day || !config.memorial_day.enable || html.search('<html') === -1 || html.search('grayscale(100%)') > -1) { | ||
return html; | ||
} | ||
|
||
const css = 'html { \ | ||
-webkit-filter: grayscale(100%); /* webkit */ \ | ||
-moz-filter: grayscale(100%); /* firefox */ \ | ||
-ms-filter: grayscale(100%); /* ie9 */ \ | ||
-o-filter: grayscale(100%); /* opera */ \ | ||
filter: grayscale(100%); \ | ||
filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); filter:gray; /* ie9- */ \ | ||
}'; | ||
|
||
const js = ` | ||
<script type="text/javascript"> | ||
(function() { | ||
var now = new Date(); | ||
var dayStr = '${ config.memorial_day.day }'; | ||
var day = dayStr ? new Date(dayStr) : new Date(); | ||
var isMemorialDay = now.getFullYear() === day.getFullYear() && now.getMonth() === day.getMonth() && now.getDay() === day.getDay(); | ||
if (isMemorialDay) { | ||
if (document.all) { | ||
window.style = '${ css }'; | ||
document.createStyleSheet('javascript:style'); | ||
} else { | ||
var style = document.createElement('style'); | ||
style.type = 'text/css'; | ||
style.innerHTML = '${ css }'; | ||
document.getElementsByTagName('HEAD').item(0).appendChild(style); | ||
} | ||
} | ||
})(); | ||
</script> | ||
`; | ||
|
||
return js + html; | ||
}; |