1// JavaScript code for the tool 2// JavaScript code for the tool 3$(document).ready(function () { 4 $("#uploadFile1").on('change', function () { 5 const file = $(this)[0].files[0]; 6 getTextFromFile(file).then((text) => { 7 if (text === "") { 8 return; 9 } 10 $("#inputText1").val(text); 11 showSelectedFile(); 12 }); 13 }); 14 $("#uploadFile2").on('change', function () { 15 const file = $(this)[0].files[0]; 16 getTextFromFile(file).then((text) => { 17 if (text === "") { 18 return; 19 } 20 $("#inputText2").val(text); 21 showSelectedFile_2(); 22 }); 23 }); 24 var preventRequest = false; 25 $("#inputURL_1").keyup(function () { 26 if ($(this).val().length > 10) { 27 const url = $(this).val(); 28 if (preventRequest) { 29 return 30 } 31 preventRequest = true; 32 if (validateURL(url)) { 33 ajaxReadTextFromURL(url).then((result) => { 34 let cleanText = cleanAndFormatHTMLText(result) 35 $("#inputText1").val(cleanText); 36 preventRequest = false; 37 }); 38 } 39 } 40 }); 41 $("#inputURL_2").keyup(function () { 42 if ($(this).val().length > 10) { 43 const url = $(this).val(); 44 if (preventRequest) { 45 return 46 } 47 preventRequest = true; 48 if (validateURL(url)) { 49 ajaxReadTextFromURL(url).then((result) => { 50 let cleanText = cleanAndFormatHTMLText(result) 51 $("#inputText2").val(cleanText); 52 preventRequest = false; 53 }); 54 } 55 } 56 }); 57 58 59 $("#uploadBtn1").click(function () { 60 $("#uploadFile1").click(); 61 }); 62 63 $("#uploadBtn2").click(function () { 64 $("#uploadFile2").click(); 65 }); 66 67 68 69 $("#checkBtn").on('click', function (e) { 70 e.preventDefault(); // Prevent the form from submitting immediately 71 compareText() 72 }); 73}); 74 75const populateTable = (data) => { 76 $('#resultsTable tbody tr:eq(1) td:eq(1)').text(data.firstVal === 'url' ? data.url1 : (data.firstVal === 'file' ? data.file1 : 'Text content used')); 77 $('#resultsTable tbody tr:eq(1) td:eq(2)').text(data.secondVal === 'url' ? data.url2 : (data.secondVal === 'file' ? data.file2 : 'Text content used')); 78 $('#first-content-match').html(data.percent1 + '%'); 79 $('#second-content-match').html(data.percent2 + '%'); 80 $('#page-content-1').html(data.page_content1); 81 $('#page-content-2').html(data.page_content2); 82 83} 84function showSelectedFile() { 85 86 var fileName = $("#uploadFile1").val().replace(/C:\\fakepath\\/i, ''); 87 $("#fileName1").attr("data-original-title", escapeHtml(fileName)); 88 if (fileName.length > 30) { 89 fileName = '...' + fileName.substr(-28, 28); 90 } 91 $("#fileName1").html(escapeHtml(fileName)); 92} 93 94function showSelectedFile_2() { 95 var fileName = $("#uploadFile2").val().replace(/C:\\fakepath\\/i, ''); 96 $("#fileName2").attr("data-original-title", escapeHtml(fileName)); 97 if (fileName.length > 30) { 98 fileName = '...' + fileName.substr(-28, 28); 99 } 100 $("#fileName2").html(escapeHtml(fileName)); 101} 102const compareText = () => { 103 const text_1 = escapeHtml($("#inputText1").val()); 104 const text_2 = escapeHtml($("#inputText2").val()); 105 if (text_1.length < 10) { 106 alertBox("warning", "No Text Found", "Please enter some text in the first section"); 107 return false; 108 } 109 if (text_2.length < 10) { 110 alertBox("warning", "No Text Found", "Please enter some text in the second section"); 111 return false; 112 } 113 const data = { 114 text_1, 115 text_2 116 } 117 if ($("#ignore_cap_latter").is(":checked")) { 118 data.text_1 = data.text_1.toLowerCase(); 119 data.text_2 = data.text_2.toLowerCase(); 120 } 121 $("#checkBtn").html('<i class="fa fa-refresh fa-spin"></i> Comparing...'); 122 123 $.ajax({ 124 type: "POST", 125 url: BASE_URL + "ajax/plagiarism-comparison-search", 126 data, 127 success: function (response) { 128 $("#ressultSec").show(); 129 populateTable(response); 130 $('html, body').animate({ 131 scrollTop: $("#ressultSec").offset().top 132 }, 10); 133 }, 134 complete: function () { 135 $("#checkBtn").html('Compare Text'); 136 } 137 }); 138} 139 140 141 142async function fetchAndValidateText(url) { 143 try { 144 // Fetch the content from the URL 145 const response = await fetch(url); 146 // Check if the response is successful (status code 200) 147 if (response.ok) { 148 // Read the response text 149 const text = await response.text(); 150 // Perform your validation checks on the 'text' variable 151 const isValid = validateText(text); 152 if (isValid) { 153 // Text is valid; return it 154 return text; 155 } else {
156 // Text is not valid; throw an error 157 throw new Error("Invalid Text"); 158 } 159 } else { 160 // Handle HTTP error 161 throw new Error(`HTTP Error: ${response.status} - ${response.statusText}`); 162 } 163 } catch (error) { 164 // Handle network or other errors 165 throw error; 166 } 167} 168 169// Function to validate the text (customize this as needed) 170const validateText = (text) => { 171 // Example: Check if the text contains at least 10 characters 172 return text.length >= 10; 173} 174function cleanAndFormatHTMLText(text) { 175 var cleanText = text.replace(/\s*\n\s*/g, "\n") 176 .replace(/\n{2,}/g, "\n") 177 .trim(); 178 return cleanText; 179}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.