aliparser

sample goods

当前为 2016-02-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name aliparser
  3. // @namespace Violentmonkey Scripts
  4. // @grant none
  5. // @description:en sample goods
  6. // @include http://*aliexpress.com/*
  7. // @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
  8. // @version 0.0.1.20160129080800
  9. // @description sample goods
  10. // ==/UserScript==
  11.  
  12. setButton()
  13.  
  14. addEnentClick()
  15.  
  16. setIframe()
  17.  
  18. function setIframe(){
  19. var iframe = '<iframe src="http://tdom.in/www/ali/" id="iframe"></iframe>';
  20. $(iframe).css({'width':'100%','height':'300px'}).prependTo('body')
  21. }
  22. function addEnentClick(){
  23. $('.addButton').click(function(){
  24. var images = $('.image-nav-item img').length?$('.image-nav-item img'):$('.ui-image-viewer-thumb-frame img');
  25. var imgs = new Array();
  26. //alert(images.length)
  27. for(var i=0;i<images.length;i++){
  28. imgs[i] = images[i].src.replace('.jpg_50x50','')
  29. }
  30. if($(this).attr('data-it')=='1'){
  31. var object = {
  32. price: $('#product-price [itemprop=highPrice]').text() || $('#product-price [itemprop=price]').text(),
  33. href:location.href,
  34. image:$('.ui-image-viewer-thumb-wrap img').attr('src'),
  35. id:$('#hid-product-id').val(),
  36. images: imgs
  37. }
  38. object.price += ' '+$('#product-price [itemprop=priceCurrency]').text()
  39. }else{
  40. var item = $(this).closest('li')
  41. var object = {
  42. price:item.find('.info [itemprop=price]').html(),
  43. href:item.find('a.picRind').attr('href'),
  44. image:item.find('.picCore').attr('src'),
  45. id:item.find('.atc-product-id').val(),
  46. images: imgs
  47. }
  48. }
  49. win = document.getElementById('iframe').contentWindow
  50. win.postMessage(object,'*')
  51.  
  52. })
  53. }
  54.  
  55. function setButton(){
  56.  
  57. var button = '<input type="button" value="ДОБАВИТЬ" class="addButton">'
  58. var appendTo ='.product-name'
  59. //var appendTo = $('.list-item').length?'.list-item':'.product-name'
  60. //if(!appendTo.length) appendTo = '.list-item'
  61. //alert(appendTo)
  62. $(button).css({'position': 'absolute','top':'0px','left':'45px','z-index':'100','background':'#EA7B7B',
  63. 'padding':'5px 20px','border':'none','margin':'4px'}).appendTo(appendTo).attr('data-it','0')
  64. if(appendTo=='.product-name')
  65. $('.addButton').css('position','static').attr('data-it','1')
  66. }