-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (59 loc) · 1.74 KB
/
Copy pathapp.js
File metadata and controls
70 lines (59 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// copy html text to clipboard
function copyToClipboard(passEle) {
document.getElementById("copyBtn").innerText="Copied!";
var copyText = document.getElementById(passEle);
copyText.select();
copyText.setSelectionRange(0, 99999);
navigator.clipboard.writeText(copyText.value);
}
//copy string to clipboard
function copySyllabus(text) {
navigator.clipboard.writeText(text);
}
$(document).ready(function() {
$('form').on('submit', function(e) {
$("#copyBtn").text('Copy')
var converter = new showdown.Converter();
var inputValue=$("#linkInput").val();
var inputValue=validateInput(inputValue);
if (inputValue!==null){
$('#submitButton').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>Loading...')
$('#validateError').hide()
req=$.ajax({
data : {
link : inputValue,
},
type : 'POST',
url : '/update'
})
req.done(function(data) {
$('#submitButton').text('Submit');
$('#markdownArea').text(data.syllabus);
$('.textTitle h2').text(data.name);
result=converter.makeHtml(data.syllabus);
$('#collapseExample').prepend(result);
});
}else{
var obj=$('#validateError').text("Valid link sample: \n https://www.udemy.com/course/100-days-of-code/ \n (Do not forget to add '/' at the end)").show();
obj.html(obj.html().replace(/\n/g,'<br/>'));
}
e.preventDefault();
});
$(".searchcopyBtn").click(function(){
currLink=$(this).parent().prev().find('a:first').attr('href');
curr_id=this.id
req=$.ajax(
{
data:{
link:currLink,
},
type:'POST',
url:'/getsyllabus',
})
req.done(function(data){
copySyllabus(data.syllabus);
$(".searchcopyBtn").text("Copy");
$("#"+curr_id).text("Copied!");
});
})
});