Snippets

Glenn Tozier Link Updater

Created by Glenn Tozier last modified
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>MPC Library outdated link landing page</title>


  </head>

	<br>

	<div id="welcome-message" style="text-align: center;">

			<h2>
				Whoops, looks like you are using an outdated link!
			</h2>
			<p>
				The MPC Library has updated their off-campus access applications, please copy the updated link below. Contact <a href="http://www.mpc.edu/library">the MPC Library</a> if you have any questions.
			</p>

	</div>
			
    <div id="content-area">
		<!-- <p id="URLoutput"></p> -->
        <div id="link-area">
		The updated URL for this resources should be: <br>
        </div>
	</div>



<script>
// Get the current URL
var currentURL = window.location.href;

// Sanitize the URL to prevent JavaScript injection because
var sanitizedURL = encodeURIComponent(currentURL);

// Find the old proxy in the URL and replace it. Update with your old and new proxy prefix
if (sanitizedURL.includes("libproxy.mpc.edu")) {
    var newURL = sanitizedURL.replace("libproxy.mpc.edu", "mpc.idm.oclc.org");
	
	// Create a hyperlink element with the new URL
    var hyperlinkdnewURL = document.createElement("a");
    hyperlinkdnewURL.href = decodeURIComponent(newURL);
    hyperlinkdnewURL.textContent = decodeURIComponent(newURL);

    // Append the hyperlink to the link-area div
    var linkArea = document.getElementById("link-area");
    if (linkArea) {
        linkArea.appendChild(hyperlinkdnewURL);
    }
	
	// Create a button to copy the new URL
    var copyButton = document.createElement("button");
    copyButton.textContent = "Copy updated link";
    copyButton.addEventListener("click", function () {
        
		// Copy the updated URL to the clipboard
		var tempTextarea = document.createElement("textarea");
		document.body.appendChild(tempTextarea);
        tempTextarea.value = decodeURIComponent(newURL);
		//alert(tempTextarea.value);
        tempTextarea.select();
        document.execCommand("copy");
        document.body.removeChild(tempTextarea);

        // Inform the user that the URL has been copied
        alert("Updated link copied to clipboard!");
    });

    // Put the button on the page
    var contentArea = document.getElementById("content-area");
    if (contentArea) {
        contentArea.appendChild(copyButton);
    }

}



// Show the new URL in the URLoutput p of the html
//document.getElementById("URLoutput").innerHTML = "The updated URL for this resources should be:<br>" + decodeURIComponent(newURL);

	
</script>



  </body>
</html>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.