DMMGirl

DMM.R18/mono/dvd tweak for non-member: show big cover, preload sample picture, local wishlist, remove member functions...

  1. // ==UserScript==
  2. // @name DMMGirl
  3. // @namespace null
  4. // @description DMM.R18/mono/dvd tweak for non-member: show big cover, preload sample picture, local wishlist, remove member functions...
  5. // @version 1.1.2
  6. // @grant GM_addStyle
  7. // @include http://www.dmm.co.jp/*
  8. // @include http://www.dmm.co.jp/mono/dvd/-/list/*
  9. // @include http://www.dmm.co.jp/top/-/error/area/*
  10. // @include http://www.dmm.co.jp/mono/dvd/-/detail/=/cid=*
  11. // ==/UserScript==
  12. var detail = {
  13. videoEnable: false,
  14. init: function(c) {
  15. GM_addStyle(' \
  16. #mybox {font-size:1.2em; font-weight:bold; background-color:#F7FDFF; border:1px solid #CCCCCC; padding:5px 10px; margin-bottom:10px;} \
  17. #mybox a {display:block; color:#005FC0; cursor:pointer; text-decoration:none; padding-left:10px; \
  18. background:url("http://p.dmm.co.jp/p/common/arrow_common.gif") no-repeat scroll left center transparent} \
  19. #mybox a:active, #mybox a:hover {color:#EE2200 !important; text-decoration:underline !important;} \
  20. #mybox a:visited {color:#990099 !important;}');
  21. this.replaceRcolumn(c.comment);
  22. this.checkVideo();
  23. this.showCover();
  24. this.addPreloadRadio(c.preload);
  25. },
  26. //==Add preload radio button==
  27. addPreloadRadio: function(c) {
  28. var headline = document.getElementsByClassName('headline mg-b10 lh3')[0];
  29. var nosample = document.querySelectorAll('span.nw')[0];
  30. if(headline && !nosample) {
  31. var link = document.createElement('input');
  32. link.type = 'radio';
  33. link.id = 'prelink';
  34. link.addEventListener('click', this.onPreloadSample, false);
  35. headline.appendChild(link);
  36. headline.appendChild(document.createTextNode('Preload '));
  37. if(c) {
  38. link.click();
  39. }
  40. }
  41. },
  42. //==Preload previews==
  43. onPreloadSample: function() {
  44. this.removeEventListener('click', detail.onPreloadSample, false);
  45. var sample = document.getElementsByName('sample-image'); //
  46. var block = document.getElementById('sample-image-block');
  47. var newblock = document.createElement('div');
  48. for(var i = 0; i < sample.length; i++) {
  49. var pic = document.createElement('img');
  50. pic.src = sample[i].firstChild.src.replace('-', 'jp-');
  51. pic.height = 73;
  52. pic.className = 'galpic';
  53. pic.addEventListener('click', gal.onShowPic, false);
  54. newblock.appendChild(pic);
  55. }
  56. block.parentNode.replaceChild(newblock, block);
  57. },
  58.  
  59. checkVideo: function() {
  60. var video = document.getElementById('sample-video');
  61. if(video.lastElementChild.tagName === 'NOSCRIPT') {
  62. this.videoEnable = true;
  63. }
  64. },
  65. //==Show big cover==
  66. showCover: function() {
  67. var sample = document.getElementsByClassName('float-l mg-b20 mg-r12')[0];
  68. var img = document.getElementsByClassName('tdmm')[0];
  69. img.src = img.src.replace('ps.jpg', 'pl.jpg');
  70. removeChildren(sample);
  71. sample.className = 'mg-b20 mg-r12';
  72. sample.appendChild(img);
  73. },
  74. replaceRcolumn: function(c) {
  75. var rcolumn = document.getElementsByClassName('vline')[0].nextElementSibling;
  76. var info = document.getElementsByClassName('mg-b20')[1];
  77. info.id = 'infot';
  78. var tbody = info.firstElementChild; //remove last 2 rows
  79. tbody.removeChild(tbody.lastElementChild);
  80. var review = document.getElementById('review');
  81. if(review) {
  82. var star = tbody.lastElementChild.lastElementChild;
  83. var vote = document.getElementsByClassName('overview')[0];
  84. if(vote && star.lastElementChild) {
  85. star.lastElementChild.innerHTML = '(' + vote.firstElementChild.lastElementChild.innerHTML + ')';
  86. } else {
  87. star.lastElementChild.innerHTML = '(0)';
  88. }
  89. if(c) {
  90. review.parentNode.removeChild(review);
  91. }
  92. }
  93. var box = document.getElementsByClassName('bx-option mg-t20')[0];
  94. if(box) {
  95. box.parentNode.removeChild(box);
  96. }
  97. var tag = document.getElementById('producttag');
  98. if(tag) {
  99. tag.parentNode.removeChild(tag);
  100. }
  101. var desc = info.nextElementSibling.nextElementSibling;
  102. var another = document.getElementsByClassName('another')[0];
  103. removeChildren(rcolumn);
  104. var div = document.createElement('div');
  105. div.id = 'mybox';
  106. var add = document.createElement('a');
  107. add.textContent = 'Add to Wishlist';
  108. add.addEventListener('click', this.onAddWish, false);
  109. var view = document.createElement('a');
  110. view.href = '/top/-/error/area/';
  111. view.textContent = 'View Wishlist';
  112. var search = document.createElement('a');
  113. search.href = 'https://www.google.com/#q=' + getCid(location.pathname, true)[0];
  114. search.target = '_blank';
  115. search.textContent = 'Google It';
  116. div.appendChild(add);
  117. div.appendChild(view);
  118. div.appendChild(search);
  119. rcolumn.appendChild(div);
  120. rcolumn.appendChild(info);
  121. rcolumn.appendChild(desc);
  122. if(another) {
  123. rcolumn.appendChild(another);
  124. }
  125. var ad = document.getElementsByClassName('mg-b12 center')[0];
  126. ad.parentNode.removeChild(ad);
  127. },
  128. //==Add to wishlist==
  129. onAddWish: function() {
  130. var tds = document.querySelectorAll('td.nw'); //[type,date,length,actress,director,series,maker,label,genre,cid]
  131. var date = tds[1].nextElementSibling;
  132. var actress = tds[3].nextElementSibling;
  133. var maker = tds[6].nextElementSibling;
  134. var cid = tds[9].nextElementSibling.innerHTML;
  135. var title = document.getElementById('title'); //get title
  136. var detail = date.innerHTML + '#' + actress.innerHTML + '#' + maker.innerHTML + '#' + title.innerHTML;
  137. localStorage.setItem(cid, detail);
  138. }
  139.  
  140.  
  141. };
  142. var list = {
  143. init: function() {
  144. var smallThumb = document.getElementsByClassName('img');
  145. for(var i = 0; i < smallThumb.length; i++) {
  146. smallThumb[i].firstElementChild.addEventListener('mouseover', this.onShowThumb, false);
  147. }
  148. var thumb = new Image();
  149. thumb.id = 'hoverpic';
  150. thumb.style.position = 'absolute';
  151. thumb.style.zIndex = 22;
  152. thumb.style.display = 'none';
  153. thumb.addEventListener('mouseout', this.onRemoveThumb, false);
  154. var a = document.createElement('a');
  155. a.appendChild(thumb);
  156. document.body.appendChild(a);
  157. },
  158. onShowThumb: function() {
  159. if(this.src.search('noimage') === -1) {
  160. var thumb = document.getElementById('hoverpic');
  161. thumb.src = this.src.replace('pt.jpg', 'ps.jpg');
  162. var pos = this.getBoundingClientRect();
  163. thumb.style.left = pos.left - 29 + window.pageXOffset + 'px'; //147*200,90*122
  164. thumb.style.top = pos.top - 39 + window.pageYOffset + 'px';
  165. thumb.width = 147;
  166. thumb.height = 200;
  167. thumb.style.display = 'block';
  168. thumb.parentNode.href = '/mono/dvd/-/detail/=/cid=' + getCid(this.src)[1] + '/';
  169. }
  170. },
  171. onRemoveThumb: function() {
  172. this.style.display = 'none';
  173. this.src = null;
  174. this.parentNode.href = null;
  175. }
  176. };
  177. var wish = {
  178. dvd: [],
  179. sortType: ['cid', 'date', 'actress', 'maker'],
  180. init: function() {
  181. document.title = 'Wishlist';
  182. GM_addStyle(' \
  183. body,table {color:#333333; font-size:12px; font-family:"MS PGothic","Osaka";} \
  184. a:link {color:#005FC0; text-decoration:none;} \
  185. a:visited {color:#005FC0; text-decoration:none;} \
  186. a:hover,a:active {color:#EE2200; text-decoration:underline;} \
  187. table {text-align:center; width:590px; border-collapse:separate; border-spacing:5px;} \
  188. table th {font-size:1.1em; padding:2px; background-color:#242424; color:#ffffff} \
  189. table th:hover {cursor:pointer} \
  190. table td {padding:2px; background-color:#F8F8F8; border:1px solid #CCCCCC;} \
  191. p {text-align:left}');
  192. document.body.innerHTML = ' \
  193. <table> \
  194. <thead> \
  195. <tr> \
  196. <th width="3%">#</th> \
  197. <th width=15%">Cover</th> \
  198. <th width="30%" id="cid">CID</th> \
  199. <th width="17%" id="actress">Actress</th> \
  200. <th width="17%" id="maker">Maker</th> \
  201. <th width="14%" id="date">Date</th> \
  202. <th width="4%">X</th> \
  203. </tr> \
  204. </thead> \
  205. <tbody id="wishlist"></tbody> \
  206. </table>';
  207. this.createObj();
  208. this.fillTable();
  209. },
  210. onSort: function() {
  211. for(var i = 0; i < 4; i++) {
  212. document.getElementById(wish.sortType[i]).style.backgroundColor = '#242424';
  213. }
  214. this.style.backgroundColor = '#C10000';
  215. wish.dvd.sort(wish.by(this.id));
  216. wish.fillTable();
  217. },
  218. by: function(type) {
  219. return function(a, b) {
  220. var c = a[type];
  221. var d = b[type];
  222. if(c === d) {
  223. return 0;
  224. }
  225. if(c < d) {
  226. return -1;
  227. } else {
  228. return 1;
  229. }
  230. };
  231. },
  232. createObj: function() {
  233. function Dvd(cid, date, actress, maker, title) {
  234. this.cid = cid;
  235. this.date = date;
  236. this.actress = actress;
  237. this.maker = maker;
  238. this.title = title;
  239. }
  240. for(var i = 0, j = 0; i < localStorage.length; i++) {
  241. var cid = localStorage.key(i);
  242. if(cid[0] !== '#' && cid[0] !== '_' && cid.slice(0,3) !== 'cX_') {
  243. var info = localStorage[cid].split('#'); //Date[0]#Actress[1]#Maker[2]#Title[3]
  244. info[1] = info[1].replace(/></g, '><br /><');
  245. this.dvd[j] = new Dvd(cid, info[0], info[1], info[2], info[3]);
  246. j++;
  247. }
  248. }
  249. this.dvd.sort(this.by('date'));
  250. },
  251. fillTable: function() {
  252. for(var i = 0; i < 4; i++) {
  253. document.getElementById(this.sortType[i]).addEventListener('click', this.onSort, false);
  254. }
  255. var list = document.getElementById('wishlist');
  256. removeChildren(list);
  257. for(i = 0; i < this.dvd.length; i++) {
  258. var item = document.createElement('tr');
  259. item.innerHTML = ' \
  260. <td height="130">' + (i + 1) + '</td> \
  261. <td><img src="http://pics.dmm.co.jp/mono/movie/' + this.dvd[i].cid + '/' + this.dvd[i].cid + 'pt.jpg" /></td> \
  262. <td><a href="/mono/dvd/-/detail/=/cid=' + this.dvd[i].cid.replace(/so$/, '') + '/">' + this.dvd[i].cid + '<br /></a><p>' + this.dvd[i].title + '</p></td> \
  263. <td>' + this.dvd[i].actress + '</td> \
  264. <td name="maker">' + this.dvd[i].maker + '</td> \
  265. <td>' + this.dvd[i].date + '</td> \
  266. <td><a href="" onclick="localStorage.removeItem(\'' + this.dvd[i].cid + '\')">' + 'X' + '</a></td>';
  267. list.appendChild(item);
  268. }
  269.  
  270. }
  271. };
  272. var fav = {
  273. menus: [],
  274. init: function() {
  275. GM_addStyle(' \
  276. #header .hd-lnav ul li ul li {float:none; margin:0; background-color:#242424; position:relative; z-index:99} \
  277. #header .hd-lnav ul li ul {display:none; position:absolute;} \
  278. #header .hd-lnav ul li>ul {top:auto; left:auto;} \
  279. #header .hd-lnav ul li:hover ul {display:block}');
  280. this.addLink();
  281. this.setMenu();
  282. },
  283. addLink: function() {
  284. var wishLink = document.createElement('a');
  285. wishLink.href = '/top/-/error/area/';
  286. wishLink.textContent = 'Wishlist';
  287. wishLink.style.marginLeft = '5px';
  288. var key = document.getElementsByClassName('popular-keyword')[0];
  289. key.appendChild(wishLink);
  290. key.style.right = '-3em';
  291. },
  292. setMenu: function() {
  293. function Menu(label, key) {
  294. this.label = label;
  295. this.key = key;
  296. }
  297. this.menus[0] = new Menu('Actress', 'actress');
  298. this.menus[1] = new Menu('Maker', 'maker');
  299. this.menus[2] = new Menu('Genre', 'keyword', '#GId', '#GName');
  300. for(var i = 0; i < this.menus.length; i++) {
  301. var type = this.menus[i].key[0];
  302. var id = '#' + type + 'ID';
  303. var name = '#' + type + 'NAME';
  304. var sid = localStorage.getItem(id);
  305. if(!sid) {
  306. localStorage.setItem(id, '[]');
  307. localStorage.setItem(name, '[]');
  308. } else {
  309. var idList = JSON.parse(sid);
  310. var nameList = JSON.parse(localStorage.getItem(name));
  311. this.createMenu(this.menus[i].label, this.menus[i].key, idList, nameList);
  312. }
  313. }
  314. },
  315. createMenu: function(label, key, id, name) {
  316. var navBar = document.getElementsByClassName('hd-lnav group')[0].firstElementChild;
  317. var liMenu = document.createElement('li');
  318. var aMenu = document.createElement('a');
  319. aMenu.href = '/mono/dvd/-/' + label.toLowerCase() + '/';
  320. aMenu.textContent = label;
  321. liMenu.appendChild(aMenu);
  322. var ulMenu = document.createElement('ul');
  323. liMenu.appendChild(ulMenu);
  324. navBar.appendChild(liMenu);
  325. for(var i = 0; i < id.length; i++) {
  326. var liSubmenu = document.createElement('li');
  327. var aSubmenu = document.createElement('a');
  328. aSubmenu.href = '/mono/dvd/-/list/=/article=' + key + '/id=' + id[i] + '/sort=date/';
  329. aSubmenu.textContent = name[i];
  330. liSubmenu.appendChild(aSubmenu);
  331. ulMenu.appendChild(liSubmenu);
  332. }
  333. }
  334. };
  335. var addfav = {
  336. init: function() {
  337. GM_addStyle(' \
  338. #dropzone {position:absolute; left:0; top:0; width:100%; height:100%;} \
  339. #dropbox {position:relative; font-size:1.2em; font-weight:bold; text-align:center; padding-top:10px; color:#005FC0; \
  340. height:30px; background-color:#F7FDFF; border:2px dashed #EE2200; margin-bottom:5px; display:none} \
  341. #dropbox.over {border:2px solid #005FC0;}');
  342. this.addFav();
  343. },
  344. addFav: function() {
  345. var actress = document.getElementById('performer');
  346. var performer = actress.querySelectorAll('a');
  347. for(var c = 0 ; c < performer.length; c++) {
  348. actress.parentNode.insertBefore(performer[c], actress);
  349. }
  350. actress.parentNode.removeChild(actress);
  351. var tds = document.getElementsByClassName('nw');
  352. var k = [3, 6, 8]; //3:actress, 6: maker, 8: genre
  353. for(var i = 0; i < k.length; i++) {
  354. var link = tds[k[i]].nextElementSibling.children;
  355. for(var j = 0; j < link.length; j++) {
  356. link[j].addEventListener('dragstart', this.onDragStart, false);
  357. link[j].addEventListener('dragend', this.onDragEnd, false);
  358. }
  359. }
  360. var info = document.getElementById('infot');
  361. var box = document.createElement('div');
  362. box.id = 'dropbox';
  363. var zone = document.createElement('div');
  364. zone.id = 'dropzone';
  365. box.appendChild(zone);
  366. box.appendChild(document.createTextNode('Drop Here'));
  367. info.parentNode.insertBefore(box, info);
  368. zone.addEventListener('dragenter', this.onDragEnter, false);
  369. zone.addEventListener('dragover', this.onDragOver, false);
  370. zone.addEventListener('dragleave', this.onDragLeave, false);
  371. zone.addEventListener('drop', this.onDrop, false);
  372. },
  373. onDragStart: function(e) {
  374. document.getElementById('dropbox').style.display = 'block';
  375. e.dataTransfer.effectAllowed = 'link';
  376. e.dataTransfer.setData('aName', this.text);
  377. e.dataTransfer.setData('aLink', this.href);
  378. },
  379. onDragOver: function(e) {
  380. e.preventDefault();
  381. e.dataTransfer.dropEffect = 'link';
  382. },
  383. onDragEnter: function() {
  384. this.parentNode.classList.add('over');
  385. },
  386. onDragLeave: function() {
  387. this.parentNode.classList.remove('over');
  388. },
  389. onDrop: function(e) {
  390. e.stopPropagation();
  391. e.preventDefault();
  392. this.classList.remove('over');
  393. var aName = e.dataTransfer.getData('aName');
  394. var aLink = e.dataTransfer.getData('aLink');
  395. var aId = aLink.match(/\d+/)[0];
  396. var aType = aLink.match(/article=([a-z])/)[1];
  397. var itemId = '#' + aType + 'ID';
  398. var itemName = '#' + aType + 'NAME';
  399. //this.innerHTML=aType + ':'aName + ',' + aId;
  400. var aIdList = JSON.parse(localStorage.getItem(itemId));
  401. if(aIdList) {
  402. if(aIdList.indexOf(aId) === -1) {
  403. aIdList.push(aId);
  404. var aNameList = JSON.parse(localStorage.getItem(itemName));
  405. aNameList.push(aName);
  406. localStorage.setItem(itemId, JSON.stringify(aIdList));
  407. localStorage.setItem(itemName, JSON.stringify(aNameList));
  408. }
  409. } else {
  410. aIdList = [];
  411. aNameList = [];
  412. }
  413. },
  414. onDragEnd: function() {
  415. document.getElementById('dropbox').style.display = 'none';
  416. }
  417. };
  418. var gal = {
  419. init: function(e, width, height) {
  420. var div = document.createElement('div');
  421. var background = document.createElement('div');
  422. background.setAttribute('style', 'position:fixed; height:100%; width:100%; left:0; top:0; background-color:black; opacity:0.8;z-index:20');
  423. background.addEventListener('click', function() {
  424. document.body.removeChild(div);
  425. }, true);
  426. var box = document.createElement('div');
  427. box.id = 'box';
  428. box.style.position = 'absolute';
  429. box.style.left = window.pageXOffset + (window.innerWidth - width) / 2 + 'px';
  430. box.style.top = window.pageYOffset + (window.innerHeight - height) / 2 + 'px';
  431. box.style.zIndex = 21;
  432. document.body.appendChild(div);
  433. div.appendChild(background);
  434. div.appendChild(box);
  435. box.appendChild(e);
  436. },
  437. //==Show preview gallery==
  438. onShowPic: function() {
  439. var origin = new Image();
  440. origin.src = this.src;
  441. var leftd = document.createElement('div');
  442. leftd.id = 'leftd';
  443. leftd.setAttribute('style', 'position:absolute; left:0; top:0; height:100%; width:50%');
  444. leftd.addEventListener('click', gal.onShowNext, true);
  445. var rightd = document.createElement('div');
  446. rightd.id = 'rightd';
  447. rightd.setAttribute('style', 'position:absolute; right:0; top:0; height:100%; width:50%');
  448. rightd.addEventListener('click', gal.onShowNext, true);
  449. var image = document.createElement('div');
  450. image.appendChild(origin);
  451. image.appendChild(leftd);
  452. image.appendChild(rightd);
  453. gal.init(image, origin.width, origin.height);
  454. },
  455. //==Show next preview==
  456. onShowNext: function() {
  457. var box = document.getElementById('box');
  458. var curpic = box.firstChild.firstChild;
  459. var gal = document.getElementsByClassName('galpic').length;
  460. var num = (this.id === 'leftd') ? -1 : 1;
  461. var patt = /\d+(?=\.jpg$)/;
  462. patt.compile(patt);
  463. var nextnum = parseInt(curpic.src.match(patt)[0], 10) + num;
  464. if(nextnum <= gal && nextnum > 0) {
  465. var nextpic = new Image();
  466. nextpic.src = curpic.src.replace(patt, nextnum);
  467. box.style.left = window.pageXOffset + (window.innerWidth - nextpic.width) / 2 + 'px';
  468. box.style.top = window.pageYOffset + (window.innerHeight - nextpic.height) / 2 + 'px';
  469. box.firstChild.insertBefore(nextpic, curpic);
  470. box.firstChild.removeChild(curpic);
  471. } else {
  472. document.body.removeChild(box.parentNode);
  473. }
  474. },
  475. onPlay: function() {
  476. var video = document.createElement('div');
  477. video.id = 'samplevideo';
  478. video.width = 560;
  479. video.height = 440;
  480. video.setAttribute('style', 'border:5px solid #FFFFFF; color: #F4F4F4; font-weight:bold;');
  481. video.textContent = 'Loading...';
  482. gal.init(video, video.width, video.height);
  483. }
  484. };
  485. var sample = {
  486. init: function() {
  487. if(detail.videoEnable) {
  488. this.createLink();
  489. }
  490. },
  491. createLink: function() {
  492. var mybox = document.getElementById('mybox');
  493. var play = document.createElement('a');
  494. play.textContent = 'Play Sample';
  495. play.addEventListener('click', gal.onPlay, false);
  496. play.addEventListener('click', sample.injectScript, false);
  497. mybox.appendChild(play);
  498. },
  499. injectScript: function() {
  500. function handelVideo() {
  501. $('#samplevideo').load(location.pathname + 'ajax=movie/');
  502. }
  503.  
  504. function closePlayer() {
  505. $('#box').parent().remove();
  506. }
  507. var inject = document.createElement('script');
  508. inject.appendChild(document.createTextNode('(' + handelVideo + ')();'));
  509. inject.appendChild(document.createTextNode(closePlayer));
  510. var sample = document.getElementsByClassName('mg-b20 mg-r12')[0];
  511. sample.parentNode.insertBefore(inject, sample);
  512. }
  513. };
  514. //Get cid of the dvd: type ? realcid : dmmcid
  515. //realcid[abcd123, abcd, 123] dmmcid[abcd123so, abcd123]
  516.  
  517.  
  518. function getCid(str, type) {
  519. return type ? str.match(/([a-z]+)([0-9]+)/) : str.match(/(\w+\d+)(?:so)?/);
  520. }
  521.  
  522. function removeChildren(e) {
  523. while(e.firstChild) {
  524. e.removeChild(e.firstChild);
  525. }
  526. }
  527.  
  528. (function() {
  529. //hide welcome
  530. GM_addStyle('#welcome {display:none !important;}');
  531. var page = /\/top\/-\/error\/area\/|\/detail\/|\/list\//.exec(location.pathname);
  532. if(page) {
  533. var config = {
  534. comment: true,
  535. //remove comments
  536. preload: false //auto preload
  537. };
  538. switch(page[0]) {
  539. case '/list/':
  540. list.init();
  541. fav.init();
  542. break;
  543. case '/top/-/error/area/':
  544. wish.init();
  545. break;
  546. case '/detail/':
  547. detail.init(config);
  548. sample.init();
  549. fav.init();
  550. addfav.init();
  551. break;
  552. }
  553. }
  554. })();