≡
by
noromanba
2016-01-11 [2016/01/11 02:53:00]
centering
@@ -2,12 +2,27 @@
* @title ≡
* @description centering
* @include http://*
+ * @include https://*
* @license MIT License http://nrm.mit-license.org/2012
* @require
*/
-(function (style) {
- // alt: style.width = '100%'; style.margin = '0 auto';
- style.marginLeft = 'auto';
- style.marginRight = 'auto';
-})(document.body.style);
+(function centering() {
+ var addStyle = (function () {
+ var parent = document.head || document.body || document.documentElement;
+ var style = document.createElement('style');
+ style.type = 'text/css';
+ parent.appendChild(style);
+ return function (css) {
+ style.appendChild(document.createTextNode(css + '\n'));
+ };
+ })();
+
+ var rule = {
+ old: 'body { width: 100%; margin: 0 auto; }',
+ auto: 'body { margin-left: auto; margin-right: auto; }',
+ fix: 'body { margin-left: 100px; margin-right: 100px; }'
+ };
+
+ addStyle(rule.fix);
+})();
(function centering() {
var addStyle = (function () {
var parent = document.head || document.body || document.documentElement;
var style = document.createElement('style');
style.type = 'text/css';
parent.appendChild(style);
return function (css) {
style.appendChild(document.createTextNode(css + '\n'));
};
})();
var rule = {
old: 'body { width: 100%; margin: 0 auto; }',
auto: 'body { margin-left: auto; margin-right: auto; }',
fix: 'body { margin-left: 100px; margin-right: 100px; }'
};
addStyle(rule.fix);
})();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。