Clip Images (DMM)
by
yksk
2012-02-04 [2012/02/04 16:23:19]
@@ -1,79 +1,87 @@
/*
- * @title Clip Images (DMM)
- * @include http://www.dmm.com/
- * @include http://www.dmm.co.jp/
- * @license MIT License
- */
-
-var image_type = /.+\.(?:jpe?g|gif|png|svg|bmp)$/,
- sources = {},
- filter;
-
-new function() {
- filter = function(src) {
- if (!/^http:\/\/pics\.dmm\.(?:co\.jp|com)\//.test(src)) return false;
-
- document.body.innerHTML.indexOf('【この作品のサンプル画像は拡大表示されません】') == -1 && (src = src.replace(/(\-\d+\.jpg)$/, 'jp$1'));
- src = src.replace(/p[st](\.jpg)$/, 'pl$1');
- return src;
- };
-
- clip_linked_image();
- if (typeof sample_spread_success != 'undefined') {
- var _sample_spread_success = sample_spread_success;
- sample_spread_success = function(response) {
- var ret = response && response.responseText ? _sample_spread_success(response) : false;
- clip_image();
- last();
- return ret;
- };
-
- sample_spread();
- }
- else {
- if (typeof sample_spread != 'undefined') {
- sample_spread();
- var timer = setInterval(function() {
- if (backHTML) {
- clip_image();
- last();
- clearInterval(timer);
- }
- }, 1000);
- }
- else {
- clip_image();
- last();
- }
- }
+@title Clip Images (DMM)
+@include http://www.dmm.com/
+@include http://www.dmm.co.jp/
+@license MIT License
+*/
+var add, add_image, add_linked_image, filter, has_large_image, process, sources, _ref;
+
+sources = [];
+
+has_large_image = !!((_ref = document.querySelector("#sample-image-block > a")) != null ? _ref.id : void 0);
+
+filter = function(src) {
+ if (/^http:\/\/pics\.dmm\.(?:co\.jp|com)\//.test(src)) {
+ has_large_image && (src = src.replace(/(\-\d+\.jpg)$/, "jp$1"));
+ return src.replace(/p[st](\.jpg)$/, "pl$1");
+ } else {
+ return;
+ }
};
-function last() {
- var images = [];
- for (var k in sources) {
- images.push('<img src="' + k + '">');
- }
- images.length ?
- (document.body.innerHTML = location.href + images.join('')) :
- alert('Image Not Found');
-}
-
-function clip_linked_image() {
- Array.prototype.slice.call(document.links).forEach(function(a) {
- var src = (image_type.exec(a.href) || [])[0];
- if (src) {
- filter && (src = filter(src));
- src && !sources[src] && (sources[src] = true);
- }
- });
-}
-
-function clip_image() {
- Array.prototype.slice.call(document.images).forEach(function(img) {
- var src = (image_type.exec(img.src) || [])[0];
- if (src) {
- filter && (src = filter(src));
- src && !sources[src] && (sources[src] = true);
- }
- });
-}
+process = function(filter) {
+ var images, src;
+ sources = sources.reverse().reduceRight(function(a, b) {
+ if (b && a.indexOf(b) === -1) {
+ return a.concat(b);
+ } else {
+ return a;
+ }
+ }, []);
+ images = (function() {
+ var _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = sources.length; _i < _len; _i++) {
+ src = sources[_i];
+ _results.push("<img src=\"" + src + "\">");
+ }
+ return _results;
+ })();
+ if (images.length) {
+ return document.body.outerHTML = "<body>" + location.href + (images.join('')) + "</body>";
+ } else {
+ return alert("Image Not Found");
+ }
+};
+
+add_linked_image = function() {
+ var a;
+ return add((function() {
+ var _i, _len, _ref2, _results;
+ _ref2 = document.links;
+ _results = [];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ a = _ref2[_i];
+ _results.push(a.href);
+ }
+ return _results;
+ })());
+};
+
+add_image = function() {
+ var img;
+ return add((function() {
+ var _i, _len, _ref2, _results;
+ _ref2 = document.images;
+ _results = [];
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ img = _ref2[_i];
+ _results.push(img.src);
+ }
+ return _results;
+ })());
+};
+
+add = function(target) {
+ var items;
+ items = Array.prototype.slice.call(target).filter(function(item) {
+ return /.+\.(?:jpe?g|gif|png|svg|bmp)$/.test(item);
+ });
+ return sources = sources.concat(filter ? items.map(filter) : items);
+};
+
+add_image();
+
+add_linked_image();
+
+process();
/*
@title Clip Images (DMM)
@include http://www.dmm.com/
@include http://www.dmm.co.jp/
@license MIT License
*/
var add, add_image, add_linked_image, filter, has_large_image, process, sources, _ref;
sources = [];
has_large_image = !!((_ref = document.querySelector("#sample-image-block > a")) != null ? _ref.id : void 0);
filter = function(src) {
if (/^http:\/\/pics\.dmm\.(?:co\.jp|com)\//.test(src)) {
has_large_image && (src = src.replace(/(\-\d+\.jpg)$/, "jp$1"));
return src.replace(/p[st](\.jpg)$/, "pl$1");
} else {
return;
}
};
process = function(filter) {
var images, src;
sources = sources.reverse().reduceRight(function(a, b) {
if (b && a.indexOf(b) === -1) {
return a.concat(b);
} else {
return a;
}
}, []);
images = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = sources.length; _i < _len; _i++) {
src = sources[_i];
_results.push("<img src=\"" + src + "\">");
}
return _results;
})();
if (images.length) {
return document.body.outerHTML = "<body>" + location.href + (images.join('')) + "</body>";
} else {
return alert("Image Not Found");
}
};
add_linked_image = function() {
var a;
return add((function() {
var _i, _len, _ref2, _results;
_ref2 = document.links;
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
a = _ref2[_i];
_results.push(a.href);
}
return _results;
})());
};
add_image = function() {
var img;
return add((function() {
var _i, _len, _ref2, _results;
_ref2 = document.images;
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
img = _ref2[_i];
_results.push(img.src);
}
return _results;
})());
};
add = function(target) {
var items;
items = Array.prototype.slice.call(target).filter(function(item) {
return /.+\.(?:jpe?g|gif|png|svg|bmp)$/.test(item);
});
return sources = sources.concat(filter ? items.map(filter) : items);
};
add_image();
add_linked_image();
process();
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。