Clip Images (DMM)
by
yksk
2012-02-04 [2012/02/04 16:23:19]
@@ -7,32 +7,62 @@
*/
var image_type = /.+\.(?:jpe?g|gif|png|svg|bmp)$/,
- images = [],
- sources = {};
+ sources = {},
+ filter;
-Array.prototype.slice.call(document.links).forEach(function(a) {
- var src = image_type.exec(a.href);
- if (src && !sources[src]) {
- sources[src] = true;
- images.push('<img src="' + src +'">');
+new function() {
+ filter = function(src) {
+ if (!/^http:\/\/pics\.dmm\.(?:co\.jp|com)\//.test(src)) return false;
+
+ return src
+ .replace(/p[st](\.jpg)$/, 'pl$1')
+ .replace(/(\-\d+\.jpg)$/, 'jp$1');
+ };
+
+ clip_linked_image();
+ if (typeof sample_spread != '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 {
+ clip_image();
+ last();
}
-});
+};
-var _sample_spread_success = sample_spread_success;
-sample_spread_success = function(response) {
- var ret = _sample_spread_success(response);
+function last() {
+ var images = [];
+ for (var k in sources) {
+ images.push('<img src="' + k + '">');
+ }
+ images.length ?
+ (document.body.innerHTML = 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 && !sources[src]) {
- sources[src] = true;
- src = src.replace(/(\-\d+\.jpg)$/, 'jp$1');
- images.push('<img src="' + src +'">');
+ if (src) {
+ filter && (src = filter(src));
+ src && !sources[src] && (sources[src] = true);
}
});
- images.length && (document.body.innerHTML = images.join(''));
-
- return ret;
-};
-
-sample_spread();
+}
/*
* @title Clip Images (DMM)
* @include http://www.dmm.com/
* @include http://www.dmm.co.jp/
* @license MIT License
* @private
*/
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;
return src
.replace(/p[st](\.jpg)$/, 'pl$1')
.replace(/(\-\d+\.jpg)$/, 'jp$1');
};
clip_linked_image();
if (typeof sample_spread != '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 {
clip_image();
last();
}
};
function last() {
var images = [];
for (var k in sources) {
images.push('<img src="' + k + '">');
}
images.length ?
(document.body.innerHTML = 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);
}
});
}
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。