≡
by
noromanba
2016-01-11 [2016/01/11 02:53:00]
centering
@@ -6,12 +6,15 @@
* @require
*/
+// TBD main content detection
+// c.f. https://github.com/hatena/extract-content-javascript
+
(function centering() {
- var addStyle = (function cc() {
+ var addStyle = (function createContainer() {
var parent = document.head || document.body || document.documentElement;
var style = document.createElement('style');
style.type = 'text/css';
- style.dataset.letName = cc.arguments.callee.caller.name; // XXX
+ style.dataset.letName = createContainer.arguments.callee.caller.name; // XXX
parent.appendChild(style);
return function (css) {
@@ -19,22 +22,20 @@
};
})();
- var createStyle = function (spec, sel) {
+ var createStyle = function (spec, selector) {
var s = [];
s = Object.keys(spec).map(function (prop) {
return (prop + ': ' + spec[prop] + ' !important; ');
});
- s.unshift((sel || '*') + ' { ');
+ s.unshift((selector || '*') + ' { ');
s.push('}');
return s.join('');
};
- var rule = {
- old: { 'width': '100%', 'margin': '0 auto' },
- aut: { 'margin-left': 'auto', 'margin-right': 'auto' },
- pix: { 'margin-left': '100px','margin-right': '100px' },
- rem: { 'margin-left': '15rem', 'margin-right': '15rem' }
- };
-
- addStyle(createStyle(rule.rem, 'body'));
-})();
+ addStyle(createStyle({
+ 'margin-left' : 'auto',
+ 'margin-right': 'auto',
+ 'max-width' : '80%',
+ 'min-width' : '640px'
+ }, 'body'));
+})();
/*
* @title ≡
* @description centering
* @include http://*
* @license MIT License http://nrm.mit-license.org/2012
* @require
*/
// TBD main content detection
// c.f. https://github.com/hatena/extract-content-javascript
(function centering() {
var addStyle = (function createContainer() {
var parent = document.head || document.body || document.documentElement;
var style = document.createElement('style');
style.type = 'text/css';
style.dataset.letName = createContainer.arguments.callee.caller.name; // XXX
parent.appendChild(style);
return function (css) {
style.appendChild(document.createTextNode(css + '\n'));
};
})();
var createStyle = function (spec, selector) {
var s = [];
s = Object.keys(spec).map(function (prop) {
return (prop + ': ' + spec[prop] + ' !important; ');
});
s.unshift((selector || '*') + ' { ');
s.push('}');
return s.join('');
};
addStyle(createStyle({
'margin-left' : 'auto',
'margin-right': 'auto',
'max-width' : '80%',
'min-width' : '640px'
}, 'body'));
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。