jquery listens for ctrl+c and right mouse button "copy" events

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>This is a test copy and paste</title>
</head>
<body>
	<div class="text-hook">
		<h1>
			Not to mention public speaking, too cautious between friends, conversations that are close to the official accent, that is, dominated by hypocrisy, and the language is tasteless and cannot achieve efficient communication. So, think back ten thousand steps, and sometimes prefer to hear more of the gaffes (or often the truth) of old friends. What I will never forget is that my lifelong confidant yelled at me after getting drunk, and even threw my sneakers when I was agitated. Politely, he was rude, but I was about to cry on the spot, knowing that he cared about me as close as he was to my heartache, which was better than making friends in the entertainment industry and commenting on current affairs at a dinner party. From then on, every time I take a sleeping pill, I think of the contribution he made to me after drinking. It can be seen that losing the big words and getting the truth back is beneficial and harmless to human relations and the world situation. ——Lin Xi, "Human Feelings and Sophistication"
		</h1>
	</div>
	
	<!-- js -->
	<script type="text/javascript" src="jquery.min.js"></script>
	<script type="text/javascript">

		// Listen for ctrl + c events
		$(document).unbind('keydown').bind('keydown', function(e){
		    if(e.ctrlKey && e.keyCode  == 67) {
		        doSomething();
		        // Return false to prevent repeated triggering of the copy event
		        return false;
		    }
		})
		
		// Copy event for right mouse button
		$(document).unbind('copy').bind('copy', function(e) {
			setTime();
    		console.log('Right-click copy and monitor success');
		});

		function doSomething(){
			setTime();
		    console.log('ctrl + c monitor success');
		}
 
		function setTime(){
			if(window.localStorage) {
				let time = localStorage.getItem('time');
				time ? time ++ : time = 1;
				localStorage.setItem('time', time);
			}
		}

	</script>
</body>
</html>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325514450&siteId=291194637