Greasemonkey script for mobile phones to enable view source. Small Button in the bottom…
- User
Greasemonkey script for mobile phones to enable view source. Small Button in the bottom right side of the page
- Assistant
Creating a Greasemonkey script to enable a "View Source" button on mobile web pages involves using JavaScript to insert a button into the DOM of a web page. Here’s a simple example of how you might create such a script:
-
Install Greasemonkey or a compatible userscript manager like Tampermonkey for your mobile browser. Note that support for userscripts on mobile browsers can be limited and might vary depending on the browser you use.
-
Create a new userscript and paste in the following code:
javascript// ==UserScript== // @name Mobile View Source Button // @namespace http://tampermonkey.net/ // @version 1.0 // @description Add a "View Source" button to mobile web pages // @author Your Name // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; // Create the button const button = document.createElement('button'); button.textContent = 'View Source'; button.style.position = 'fixed'; button.style.bottom = '10px'; button.style.right = '10px'; button.style.zIndex = '1000'; button.style.padding = '10px'; button.style.backgroundColor = '#444'; button.style.color = '#fff'; button.style.border = 'none'; button.style.borderRadius = '5px'; button.style.cursor = 'pointer'; // Add button to the page document.body.appendChild(button); // Add click event to button to open source code in a new window button.addEventListener('click', function() { const sourceWindow = window.open(); sourceWindow.document.open(); sourceWindow.document.write('<html><body><pre>' + escapeHTML(document.documentElement.outerHTML) + '</pre></body></html>'); sourceWindow.document.close(); }); // Function to escape HTML entities function escapeHTML(html) { return html.replace(/&/g, '&') .replace(/</g, '<') .replace(/>/g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } })(); -
- User
It needs to format the code, have line numbers and have syntax highlighting. Selection and copy does not include the line numbers
- Assistant
- User
It needs to support automatic line wrapping and have a copy source and close button
- Assistant
- User
The line wrapping needs to respect the code syntax, maybe prism have this feature. Also the view source button does not need to be visible when the source is in view
- Assistant
- User
New Greasemonkey script: clicking a link from the page opens files in line, pdf support using a js library and have a feature to let the user highlight text and make anki flash cards based on the collection of highlighted text
- Assistant