aliparser (http and https)

select producy on aliexpress then post it to vk.com album

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