A copyright violation detector running on Wikimedia Cloud Services https://tools.wmflabs.org/copyvios/
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

336 satır
9.5 KiB

  1. function updateScreenSize() {
  2. var cache = cacheCookie();
  3. var data = {
  4. "width": window.screen.availWidth,
  5. "height": window.screen.availHeight
  6. }
  7. if (!cache || cache["width"] != data["width"] || cache["height"] != data["height"]) {
  8. setCookie("CopyviosScreenCache", JSON.stringify(data), 1095);
  9. }
  10. }
  11. function cacheCookie() {
  12. var cookie = getCookie("CopyviosScreenCache");
  13. if (cookie) {
  14. try {
  15. data = JSON.parse(cookie);
  16. var width = data.width;
  17. var height = data.height;
  18. if (width && height) {
  19. return {"width": width, "height": height};
  20. }
  21. }
  22. catch (SyntaxError) {}
  23. }
  24. return false;
  25. }
  26. // Cookie code partially based on http://www.quirksmode.org/js/cookies.html
  27. function getCookie(name) {
  28. var nameEQ = name + "=";
  29. var ca = document.cookie.split(";");
  30. for (var i = 0; i < ca.length; i++) {
  31. var c = ca[i];
  32. while (c.charAt(0) == " ") {
  33. c = c.substring(1, c.length);
  34. }
  35. if (c.indexOf(nameEQ) == 0) {
  36. var value = window.atob(c.substring(nameEQ.length, c.length));
  37. if (value.indexOf("--cpv2") == 0) {
  38. return value.substring("--cpv2".length, value.length);
  39. }
  40. }
  41. }
  42. return null;
  43. }
  44. function setCookieWithDate(name, value, date) {
  45. value = window.btoa("--cpv2" + value);
  46. if (date) {
  47. var expires = ";expires=" + date.toUTCString();
  48. }
  49. else {
  50. var expires = "";
  51. }
  52. document.cookie = name + "=" + value + expires + ";path=/;samesite=lax";
  53. }
  54. function setCookie(name, value, days) {
  55. if (days) {
  56. var date = new Date();
  57. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  58. setCookieWithDate(name, value, date);
  59. }
  60. else {
  61. setCookieWithDate(name, value);
  62. }
  63. }
  64. function selectTab(e) {
  65. var tab = $(e.target);
  66. if (tab.hasClass("oo-ui-optionWidget-selected")) {
  67. return false;
  68. }
  69. var name = tab.data("name");
  70. var menu = tab.closest(".oo-ui-menuLayout");
  71. menu.find(".oo-ui-optionWidget-selected")
  72. .removeClass("oo-ui-optionWidget-selected")
  73. .attr("aria-selected", "false");
  74. tab.addClass("oo-ui-optionWidget-selected")
  75. .attr("aria-selected", "true");
  76. menu.find(".oo-ui-tabPanelLayout-active")
  77. .removeClass("oo-ui-tabPanelLayout-active")
  78. .addClass("oo-ui-element-hidden")
  79. .attr("aria-hidden", "true");
  80. menu.find('.oo-ui-tabPanelLayout[data-name="' + name + '"]')
  81. .addClass("oo-ui-tabPanelLayout-active")
  82. .removeClass("oo-ui-element-hidden")
  83. .removeAttr("aria-hidden");
  84. return false;
  85. }
  86. function submitForm() {
  87. $("#cv-form button[type='submit']")
  88. .prop("disabled", true)
  89. .css("cursor", "progress")
  90. .parent()
  91. .addClass("oo-ui-widget-disabled")
  92. .removeClass("oo-ui-widget-enabled");
  93. }
  94. function toggleNotice() {
  95. var details = $("#notice-collapse-box"),
  96. trigger = $("#notice-collapse-trigger");
  97. if (details.is(":hidden")) {
  98. details.show();
  99. trigger.text("[hide]");
  100. }
  101. else {
  102. details.hide();
  103. trigger.text("[show]");
  104. }
  105. }
  106. function setNotice() {
  107. var details = $("#notice-collapse-box"),
  108. trigger = $("#notice-collapse-trigger");
  109. if (details.length >= 0 && trigger.length >= 0) {
  110. trigger.replaceWith($("<a>", {
  111. id: "notice-collapse-trigger",
  112. href: "#",
  113. text: "[show]",
  114. click: function() {
  115. toggleNotice();
  116. return false;
  117. }
  118. }));
  119. details.hide();
  120. }
  121. }
  122. function addUrl() {
  123. var template = $("#compare-new-url");
  124. var widget = template[0].content.cloneNode(true);
  125. $(widget).find("input").prop("name", "url" + ($(".compare-url").length + 1));
  126. $(widget).find(".compare-remove-url").click(removeUrl);
  127. template.before(widget);
  128. return false;
  129. }
  130. function removeUrl(e) {
  131. $(e.target).closest(".oo-ui-layout").remove();
  132. $(".compare-url:not(.compare-url-first)").each(function(i, e) {
  133. $(e).find("input").prop("name", "url" + (i + 2));
  134. });
  135. return false;
  136. }
  137. function pasteText() {
  138. // TODO
  139. return false;
  140. }
  141. function uploadFile() {
  142. // TODO
  143. return false;
  144. }
  145. function selectResult(n) {
  146. var select = $(".cv-chain-source-" + n);
  147. if (select.length === 0) {
  148. return;
  149. }
  150. $(".cv-chain-source").addClass("hidden");
  151. select.removeClass("hidden");
  152. $(".source-row-selected").removeClass("source-row-selected");
  153. $($(".source-row")[n - 1]).addClass("source-row-selected");
  154. $(".source-tooltip > .tooltip-align-right").remove();
  155. $(".source-tooltip-selected").removeClass("source-tooltip-selected");
  156. $(".source-tooltip").filter(function(i, elem) {
  157. return elem.dataset.id === n.toString();
  158. }).addClass("source-tooltip-selected");
  159. }
  160. function setResultSelectionHandlers() {
  161. $(".source-compare").click(function(e) {
  162. selectResult($(e.target).data("id"));
  163. return false;
  164. });
  165. $("#cv-result-sources tr:not(:first-child)").click(function(e) {
  166. if (e.target.tagName === "TD") {
  167. selectResult($(e.target).parent().data("id"));
  168. return false;
  169. }
  170. });
  171. }
  172. function toggleSource(e) {
  173. var el = $(e.target),
  174. id = el.data("id");
  175. if (el.hasClass("cv-hl")) {
  176. $(".cv-hl-" + id)
  177. .addClass("cv-hl-disabled-" + id)
  178. .removeClass(["cv-hl-" + id, "cv-hl"]);
  179. } else {
  180. $(".cv-hl-disabled-" + id)
  181. .addClass(["cv-hl-" + id, "cv-hl"])
  182. .removeClass("cv-hl-disabled-" + id);
  183. }
  184. return false;
  185. }
  186. function unselectRegions() {
  187. if ($(".source-tooltip, .cv-selected").length > 0) {
  188. $(".source-tooltip").remove();
  189. $(".cv-selected").removeClass("cv-selected");
  190. return false;
  191. }
  192. }
  193. function selectRegion(e) {
  194. unselectRegions();
  195. var target = $(e.target).closest(".cv-hl");
  196. if (target.length === 0) {
  197. return;
  198. }
  199. var hls = [].slice.apply(target[0].classList).filter(function(c) {
  200. return c.startsWith("cv-hl-");
  201. });
  202. if (hls.length === 0) {
  203. return;
  204. }
  205. var num = parseInt(hls[0].substr(6));
  206. var url = null, selected = true;
  207. if ($("#cv-result-sources").length > 0) {
  208. url = $(".source-url-" + num);
  209. if (url.length === 0) {
  210. return;
  211. }
  212. selected = $(".source-row-selected").data("id") === num;
  213. }
  214. var wordcount = target.text().split(/\s+/).filter(function(s) { return s != '' }).length;
  215. var width;
  216. var contents = $("<span>");
  217. if (url !== null) {
  218. var domain = url.data("domain") || url.text();
  219. contents.append(
  220. $("<a>", {
  221. class: "selector",
  222. href: "#",
  223. title: "Select source",
  224. })
  225. .text("Source " + num)
  226. .click(function() {
  227. selectResult(num);
  228. return false;
  229. })
  230. ).append(
  231. $("<strong>", {class: "selector"})
  232. .text("Source " + num)
  233. ).append(" ")
  234. .append(
  235. $("<span>", {class: "domain"})
  236. .text("(" + domain + "):")
  237. ).append(" ");
  238. width = Math.min(15 + domain.length / 2, 30);
  239. } else {
  240. width = 8;
  241. }
  242. contents
  243. .append(
  244. $("<span>", {class: "wordcount"})
  245. .text(wordcount.toString() + " words")
  246. ).click(function() {
  247. if ($(".source-row-selected").data("id") === num) {
  248. unselectRegions();
  249. } else {
  250. selectResult(num);
  251. }
  252. return false;
  253. });
  254. var container = $("#source-tooltips");
  255. var containerOffset = container.offset();
  256. var chain = target.closest(".cv-chain-cell");
  257. var tooltipDirection = chain.hasClass("cv-chain-source") ? "right" : "left";
  258. var tooltip = $("<div>", {class: "source-tooltip tooltip-anchor-fixed"})
  259. .css({
  260. top: (e.pageY - containerOffset.top) + "px",
  261. left: (e.pageX - containerOffset.left) + "px",
  262. })
  263. .append(
  264. $("<span>", {class: "tooltip tooltip-align-" + tooltipDirection})
  265. .css({
  266. width: width + "em",
  267. }).append(contents)
  268. ).appendTo(container)
  269. .attr("data-id", num.toString());
  270. if (selected) {
  271. tooltip.addClass("source-tooltip-selected");
  272. }
  273. target.addClass("cv-selected");
  274. return false;
  275. }
  276. function hideAdditionalSources() {
  277. if ($("#cv-additional").length >= 0) {
  278. $("#cv-additional").css("display", "block");
  279. $(".source-default-hidden").css("display", "none");
  280. $("#show-additional-sources").click(function() {
  281. $(".source-default-hidden").css("display", "");
  282. $("#cv-additional").css("display", "none");
  283. return false;
  284. });
  285. }
  286. }
  287. $(document).ready(function() {
  288. $(".oo-ui-optionWidget").click(selectTab);
  289. $("#compare-add-url").click(addUrl);
  290. $("#compare-paste").click(pasteText);
  291. $("#compare-upload").click(uploadFile);
  292. $(".compare-remove-url").click(removeUrl);
  293. setResultSelectionHandlers();
  294. $(".source-num-included").click(toggleSource);
  295. $(".cv-chain-cell .cv-hl").click(selectRegion);
  296. $("body").click(unselectRegions);
  297. $(document).keyup(function(e) {
  298. if (e.key === "Escape") {
  299. return unselectRegions();
  300. }
  301. });
  302. $("#cv-form").submit(submitForm);
  303. hideAdditionalSources();
  304. setNotice();
  305. });