AliBetterReviews

User script for making Aliexpress reviews easier to browse

  1. // ==UserScript==
  2. // @name AliBetterReviews
  3. // @namespace kneels
  4. // @include https://feedback.aliexpress.com/*
  5. // @version 1.1
  6. // @grant none
  7. // @description User script for making Aliexpress reviews easier to browse
  8. // ==/UserScript==
  9.  
  10. var ownerMemberId = -1,
  11. productId = -1;
  12. var withPics = false,
  13. withInfo = false,
  14. withMoreInfo = false,
  15. myCountry = false;
  16. var sortval = "sortdefault@feedback",
  17. starFilter = "all+Stars",
  18. translate = "+Y+";
  19. var currentPage = 1;
  20. var imagesExpanded = false;
  21.  
  22. function appendNextPage() {
  23. var http = new XMLHttpRequest();
  24. var url = "https://feedback.aliexpress.com/display/productEvaluation.htm";
  25. var params = "productId=" + productId + "&ownerMemberId=" + ownerMemberId + "&page=" + ++currentPage
  26. + "&withPersonalInfo=" + withInfo + "&withPictures=" + withPics
  27. + "&withAdditionalFeedback=" + withMoreInfo + "&onlyFromMyCountry=" + myCountry
  28. + "&evaSortValue=" + sortVal + "&evaStarFilterValue=" + starFilter + "&translate=" + translate;
  29. http.open("POST", url, true);
  30. http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  31. http.onreadystatechange = function() {
  32. if (http.readyState == 4 && http.status == 200) {
  33. var tempDiv = document.createElement('div');
  34. tempDiv.innerHTML = http.responseText;
  35. var newFeedbackList = tempDiv.getElementsByClassName('feedback-list-wrap')[0];
  36. if (newFeedbackList.getElementsByClassName('no-feedback').length > 0) {
  37. console.log('no more pages to load');
  38. return;
  39. }
  40. var parent = document.getElementById('transction-feedback');
  41. var beforeThisNode = document.getElementById('complex-pager');
  42. if (imagesExpanded) {
  43. expandAllImages(newFeedbackList);
  44. }
  45. parent.insertBefore(newFeedbackList, beforeThisNode);
  46. }
  47. }
  48. http.send(params);
  49. console.log(http);
  50. }
  51.  
  52. function expandAllImages(doc) {
  53. var photoLists = doc.querySelectorAll('.r-photo-list');
  54. for (var i = 0; i < photoLists.length; ++i) {
  55. var picItems = photoLists[i].querySelectorAll('.pic-view-item');
  56. var html = "";
  57. for (var k = 0; k < picItems.length; ++k) {
  58. var imgUrl = picItems[k].getElementsByTagName('img')[0].src;
  59. html += '<img src="' + imgUrl + '">';
  60. }
  61. photoLists[i].innerHTML = html;
  62. }
  63. }
  64.  
  65. function inIframe() {
  66. try {
  67. return window.self !== window.top;
  68. } catch (e) {
  69. return true;
  70. }
  71. }
  72.  
  73. window.onload = function() {
  74. ownerMemberId = document.getElementById('ownerMemberId').value;
  75. productId = document.getElementById('productId').value;
  76. withPics = document.getElementById('withPictures').value;
  77. withInfo = document.getElementById('withPersonalInfo').value;
  78. withMoreInfo = document.getElementById('withAdditionalFeedback').value;
  79. myCountry = document.getElementById('onlyFromMyCountry').value;
  80. sortVal = document.getElementById('evaSortValue').value;
  81. starFilter = document.getElementById('evaStarFilterValue').value;
  82. translate = document.getElementById('translate').value;
  83. var waitTimer = setInterval(function() {
  84. var feedback = document.getElementById('transction-feedback');
  85. if (feedback !== null) {
  86. // Feedback is done loading
  87. clearInterval(waitTimer);
  88.  
  89. var filterList = document.getElementsByClassName('f-filter-list')[0];
  90.  
  91. if (inIframe()) {
  92. var fsButt = document.createElement('button');
  93. fsButt.innerHTML = "Fullscreen";
  94. filterList.appendChild(fsButt);
  95. fsButt.onclick = function() {
  96. var url = "https://feedback.aliexpress.com/display/productEvaluation.htm?productId="
  97. + productId + "&ownerMemberId=" + ownerMemberId + "&page=1"
  98. + "&withPersonalInfo=" + withInfo + "&withPictures=" + withPics
  99. + "&withAdditionalFeedback=" + withMoreInfo + "&onlyFromMyCountry=" + myCountry
  100. + "&evaSortValue=" + sortVal + "&evaStarFilterValue=" + starFilter + "&translate=" + translate;
  101. window.open(url, '_blank');
  102. };
  103. } else {
  104. var expandButt = document.createElement('button');
  105. expandButt.innerHTML = "Expand All Images";
  106. filterList.appendChild(expandButt);
  107. expandButt.onclick = function() {
  108. if (!imagesExpanded) {
  109. expandAllImages(document);
  110. imagesExpanded = true;
  111. expandButt.disabled = true;
  112. }
  113. };
  114. // endless scrolling
  115. window.onscroll = function(ev) {
  116. if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
  117. appendNextPage();
  118. }
  119. };
  120. }
  121.  
  122. }
  123. }, 500);
  124. };