-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-images-dmm.bookmarklet.coffee
52 lines (40 loc) · 1.34 KB
/
list-images-dmm.bookmarklet.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
###
@title List Images (DMM)
@include http://www.dmm.com/*
@include http://www.dmm.co.jp/*
@license MIT License
###
# DMM
# - Array.reduce を独自に prototype 拡張していて、しかも機能が違う( .com のみ)
# - Array.reduceRight は生きているので array.reverse().reduceRight する
# - .com は Prototype.js
# - .no.jp は jQuery
sources = []
has_large_image = !!document.querySelector("#sample-image-block > a")?.id
filter = (src) ->
if /^http:\/\/pics\.dmm\.(?:co\.jp|com)\//.test src
has_large_image and src = src.replace /(\-\d+\.jpg)$/, "jp$1"
src.replace /p[st](\.jpg)$/, "pl$1"
else
undefined
process = ->
sources = sources.reverse().reduceRight (a, b) ->
if b and a.indexOf(b) is -1 then a.concat b else a
, []
images = for src in sources
"#{src}\n<img src=\"#{src}\">\n"
if images.length
document.body.outerHTML = "<body>#{images.join ''}</body>"
else
alert "Image Not Found"
add_linked_image = ->
add(a.href for a in document.links)
add_image = ->
add(img.src for img in document.querySelectorAll(".page-detail > table img"))
add = (target) ->
items = Array.prototype.slice.call(target).filter (item) ->
/.+\.(?:jpe?g|gif|png|svg|bmp)$/.test item
sources = sources.concat if filter then items.map(filter) else items
add_image()
add_linked_image()
process()