2021-07-24 00:39:37 +03:00
|
|
|
import * as API from "./api.js";
|
|
|
|
import * as Notifications from "./notifications.js";
|
|
|
|
import * as Spinner from "./spinner.js";
|
|
|
|
import * as Animation from "./animation.js";
|
2021-07-30 22:24:08 +03:00
|
|
|
import * as Encryption from "./encryption.js";
|
2022-01-29 20:25:01 +03:00
|
|
|
import * as Duration from "./duration.js";
|
2021-07-24 00:39:37 +03:00
|
|
|
|
|
|
|
const CODE_ELEMENT = document.getElementById("code");
|
|
|
|
const LINE_NUMBERS_ELEMENT = document.getElementById("linenos");
|
|
|
|
const INPUT_ELEMENT = document.getElementById("input");
|
|
|
|
|
2022-01-29 20:25:01 +03:00
|
|
|
const LIFETIME_CONTAINER_ELEMENT = document.getElementById("lifetime_container");
|
|
|
|
|
2022-01-30 17:22:38 +03:00
|
|
|
const CHARACTER_AMOUNT_ELEMENT = document.getElementById("characters");
|
|
|
|
const LINES_AMOUNT_ELEMENT = document.getElementById("lines");
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
const BUTTONS_DEFAULT_ELEMENT = document.getElementById("buttons_default");
|
|
|
|
const BUTTON_NEW_ELEMENT = document.getElementById("btn_new");
|
|
|
|
const BUTTON_SAVE_ELEMENT = document.getElementById("btn_save");
|
|
|
|
const BUTTON_EDIT_ELEMENT = document.getElementById("btn_edit");
|
|
|
|
const BUTTON_DELETE_ELEMENT = document.getElementById("btn_delete");
|
|
|
|
const BUTTON_COPY_ELEMENT = document.getElementById("btn_copy");
|
|
|
|
|
|
|
|
const BUTTON_REPORT_ELEMENT = document.getElementById("btn_report");
|
|
|
|
|
|
|
|
const BUTTONS_EDIT_ELEMENT = document.getElementById("buttons_edit");
|
|
|
|
const BUTTON_EDIT_CANCEL_ELEMENT = document.getElementById("btn_edit_cancel");
|
|
|
|
const BUTTON_EDIT_APPLY_ELEMENT = document.getElementById("btn_edit_apply");
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
const BUTTON_TOGGLE_ENCRYPTION_ELEMENT = document.getElementById("btn_toggle_encryption");
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
let PASTE_ID;
|
|
|
|
let LANGUAGE;
|
|
|
|
let CODE;
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
let ENCRYPTION_KEY;
|
|
|
|
let ENCRYPTION_IV;
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
let EDIT_MODE = false;
|
|
|
|
|
|
|
|
let API_INFORMATION = {
|
|
|
|
version: "error",
|
2022-01-29 20:25:01 +03:00
|
|
|
pasteLifetime: -1,
|
2021-07-24 00:39:37 +03:00
|
|
|
modificationTokens: false,
|
|
|
|
reports: false
|
|
|
|
};
|
|
|
|
|
|
|
|
// Initializes the state system
|
|
|
|
export async function initialize() {
|
|
|
|
loadAPIInformation();
|
|
|
|
|
|
|
|
setupButtonFunctionality();
|
|
|
|
setupKeybinds();
|
|
|
|
|
2021-10-13 19:06:15 +03:00
|
|
|
// When embedded inside an iframe, add "embedded"
|
|
|
|
// class to body element.
|
|
|
|
if (window != window.parent) {
|
|
|
|
document.body.classList += " embedded";
|
|
|
|
}
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
// Enable encryption if enabled from last session
|
|
|
|
if (localStorage.getItem("encryption") === "true") {
|
|
|
|
BUTTON_TOGGLE_ENCRYPTION_ELEMENT.classList.add("active");
|
|
|
|
}
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
if (location.pathname !== "/") {
|
|
|
|
// Extract the paste data (ID and language)
|
|
|
|
const split = location.pathname.replace("/", "").split(".");
|
|
|
|
const pasteID = split[0];
|
|
|
|
const language = split[1];
|
|
|
|
|
|
|
|
// Try to retrieve the paste data from the API
|
|
|
|
const response = await API.getPaste(pasteID);
|
|
|
|
if (!response.ok) {
|
|
|
|
Notifications.error("Could not load paste: <b>" + await response.text() + "</b>");
|
|
|
|
setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the persistent paste data
|
|
|
|
PASTE_ID = pasteID;
|
|
|
|
LANGUAGE = language;
|
2021-07-30 22:24:08 +03:00
|
|
|
|
|
|
|
// Decode the response and decrypt the content if needed
|
|
|
|
const json = await response.json();
|
|
|
|
CODE = json.content;
|
|
|
|
if (json.metadata.pf_encryption) {
|
|
|
|
ENCRYPTION_KEY = location.hash.replace("#", "");
|
|
|
|
while (ENCRYPTION_KEY.length == 0) {
|
|
|
|
ENCRYPTION_KEY = prompt("Your decryption key:");
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
CODE = await Encryption.decrypt(ENCRYPTION_KEY, json.metadata.pf_encryption.iv, CODE);
|
|
|
|
ENCRYPTION_IV = json.metadata.pf_encryption.iv;
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
2022-01-30 17:12:34 +03:00
|
|
|
Notifications.error("Could not decrypt paste; make sure the decryption key is correct.");
|
2021-07-30 22:24:08 +03:00
|
|
|
setTimeout(() => location.replace(location.protocol + "//" + location.host), 3000);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-07-24 00:39:37 +03:00
|
|
|
|
|
|
|
// Fill the code block with the just received data
|
|
|
|
updateCode();
|
|
|
|
} else {
|
|
|
|
// Give the user the opportunity to paste his code
|
|
|
|
INPUT_ELEMENT.classList.remove("hidden");
|
|
|
|
INPUT_ELEMENT.focus();
|
2022-01-29 20:25:01 +03:00
|
|
|
LIFETIME_CONTAINER_ELEMENT.classList.remove("hidden");
|
2021-07-24 00:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the state of the buttons to match the current state
|
|
|
|
updateButtonState();
|
2021-07-28 14:21:08 +03:00
|
|
|
|
|
|
|
INPUT_ELEMENT.addEventListener("input", () => {
|
|
|
|
updateLineNumbers(INPUT_ELEMENT.value);
|
2022-01-30 17:22:38 +03:00
|
|
|
|
2022-01-30 17:12:34 +03:00
|
|
|
if (BUTTON_SAVE_ELEMENT.hasAttribute("disabled") && INPUT_ELEMENT.value.length > 0) {
|
|
|
|
BUTTON_SAVE_ELEMENT.removeAttribute("disabled");
|
|
|
|
}
|
|
|
|
if (!BUTTON_SAVE_ELEMENT.hasAttribute("disabled") && INPUT_ELEMENT.value.length == 0) {
|
|
|
|
BUTTON_SAVE_ELEMENT.setAttribute("disabled", true);
|
|
|
|
}
|
2021-07-28 14:21:08 +03:00
|
|
|
});
|
2021-07-24 00:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Loads the API information
|
|
|
|
async function loadAPIInformation() {
|
|
|
|
// try to retrieve the API information
|
|
|
|
const response = await API.getAPIInformation();
|
|
|
|
if (response.ok) {
|
|
|
|
API_INFORMATION = await response.json();
|
|
|
|
} else {
|
|
|
|
Notifications.error("Failed loading API information: <b>" + await response.text() + "</b>");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the API version
|
|
|
|
document.getElementById("version").innerText = API_INFORMATION.version;
|
2022-01-29 20:25:01 +03:00
|
|
|
|
|
|
|
// Display the paste lifetime
|
|
|
|
document.getElementById("lifetime").innerText = Duration.format(API_INFORMATION.pasteLifetime);
|
2021-07-24 00:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the current persistent code to the code block, highlights it and updates the line numbers
|
|
|
|
function updateCode() {
|
|
|
|
CODE_ELEMENT.innerHTML = LANGUAGE
|
|
|
|
? hljs.highlight(LANGUAGE, CODE).value
|
|
|
|
: hljs.highlightAuto(CODE).value;
|
2021-07-28 14:21:08 +03:00
|
|
|
updateLineNumbers(CODE);
|
|
|
|
}
|
2021-07-24 00:39:37 +03:00
|
|
|
|
2021-07-28 14:21:08 +03:00
|
|
|
function updateLineNumbers(content) {
|
2022-01-30 17:22:38 +03:00
|
|
|
CHARACTER_AMOUNT_ELEMENT.innerText = content.length;
|
|
|
|
LINES_AMOUNT_ELEMENT.innerText = content.split(/\n/).length;
|
|
|
|
|
2021-07-28 14:21:08 +03:00
|
|
|
if (content == "") {
|
|
|
|
LINE_NUMBERS_ELEMENT.innerHTML = "<span>></span>";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
LINE_NUMBERS_ELEMENT.innerHTML = content.split(/\n/).map((_, index) => `<span>${index + 1}</span>`).join("");
|
2021-07-24 00:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the button state according to the current state
|
|
|
|
function updateButtonState() {
|
|
|
|
if (PASTE_ID) {
|
|
|
|
BUTTON_SAVE_ELEMENT.setAttribute("disabled", true);
|
|
|
|
BUTTON_EDIT_ELEMENT.removeAttribute("disabled");
|
|
|
|
BUTTON_DELETE_ELEMENT.removeAttribute("disabled");
|
|
|
|
BUTTON_COPY_ELEMENT.removeAttribute("disabled");
|
|
|
|
|
|
|
|
if (API_INFORMATION.reports) {
|
|
|
|
BUTTON_REPORT_ELEMENT.classList.remove("hidden");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
BUTTON_EDIT_ELEMENT.setAttribute("disabled", true);
|
|
|
|
BUTTON_DELETE_ELEMENT.setAttribute("disabled", true);
|
|
|
|
BUTTON_COPY_ELEMENT.setAttribute("disabled", true);
|
|
|
|
|
|
|
|
if (API_INFORMATION.reports) {
|
|
|
|
BUTTON_REPORT_ELEMENT.classList.add("hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggles the edit mode
|
|
|
|
function toggleEditMode() {
|
|
|
|
if (EDIT_MODE) {
|
|
|
|
EDIT_MODE = false;
|
|
|
|
INPUT_ELEMENT.classList.add("hidden");
|
2022-01-29 20:25:01 +03:00
|
|
|
LIFETIME_CONTAINER_ELEMENT.classList.add("hidden");
|
2021-07-24 00:39:37 +03:00
|
|
|
CODE_ELEMENT.classList.remove("hidden");
|
2021-07-28 14:21:08 +03:00
|
|
|
updateLineNumbers(CODE);
|
2021-07-24 00:39:37 +03:00
|
|
|
Animation.animate(BUTTONS_EDIT_ELEMENT, "animate__fadeOutDown", "0.3s", () => {
|
|
|
|
BUTTONS_EDIT_ELEMENT.classList.add("hidden");
|
|
|
|
BUTTONS_DEFAULT_ELEMENT.classList.remove("hidden");
|
|
|
|
Animation.animate(BUTTONS_DEFAULT_ELEMENT, "animate__fadeInDown", "0.3s");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
EDIT_MODE = true;
|
|
|
|
CODE_ELEMENT.classList.add("hidden");
|
2022-01-29 20:25:01 +03:00
|
|
|
LIFETIME_CONTAINER_ELEMENT.classList.remove("hidden");
|
2021-07-24 00:39:37 +03:00
|
|
|
INPUT_ELEMENT.classList.remove("hidden");
|
|
|
|
INPUT_ELEMENT.value = CODE;
|
|
|
|
INPUT_ELEMENT.focus();
|
|
|
|
Animation.animate(BUTTONS_DEFAULT_ELEMENT, "animate__fadeOutUp", "0.3s", () => {
|
|
|
|
BUTTONS_DEFAULT_ELEMENT.classList.add("hidden");
|
|
|
|
BUTTONS_EDIT_ELEMENT.classList.remove("hidden");
|
|
|
|
Animation.animate(BUTTONS_EDIT_ELEMENT, "animate__fadeInUp", "0.3s");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets up the keybinds for the buttons
|
|
|
|
function setupKeybinds() {
|
|
|
|
window.addEventListener("keydown", (event) => {
|
|
|
|
// All keybinds in the default button set include the CTRL key
|
2023-01-18 23:59:10 +03:00
|
|
|
if ((EDIT_MODE && !event.ctrlKey && !event.metaKey && event.code !== "Escape") || (!EDIT_MODE && !event.ctrlKey && !event.metaKey)) {
|
2021-07-24 00:39:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the DOM element of the button to trigger
|
|
|
|
let element;
|
|
|
|
if (EDIT_MODE) {
|
|
|
|
switch (event.code) {
|
|
|
|
case "Escape": {
|
|
|
|
element = BUTTON_EDIT_CANCEL_ELEMENT;
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case "KeyS": {
|
|
|
|
element = BUTTON_EDIT_APPLY_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (event.code) {
|
|
|
|
case "KeyQ": {
|
|
|
|
element = BUTTON_NEW_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "KeyS": {
|
|
|
|
element = BUTTON_SAVE_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "KeyO": {
|
|
|
|
element = BUTTON_EDIT_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "KeyX": {
|
|
|
|
element = BUTTON_DELETE_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "KeyB": {
|
|
|
|
element = BUTTON_COPY_ELEMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trigger the found button
|
|
|
|
if (element) {
|
|
|
|
event.preventDefault();
|
|
|
|
if (element.hasAttribute("disabled")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Additionally fix the behaviour of the Tab key
|
|
|
|
window.addEventListener("keydown", (event) => {
|
|
|
|
if (event.code != "Tab") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
insertTextAtCursor(inputElement, " ");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets up the different button functionalities
|
|
|
|
function setupButtonFunctionality() {
|
|
|
|
BUTTON_NEW_ELEMENT.addEventListener("click", () => location.replace(location.protocol + "//" + location.host));
|
|
|
|
|
|
|
|
BUTTON_SAVE_ELEMENT.addEventListener("click", () => {
|
|
|
|
Spinner.surround(async () => {
|
|
|
|
// Only proceed if the input is not empty
|
|
|
|
if (!INPUT_ELEMENT.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
// Encrypt the paste if needed
|
|
|
|
let value = INPUT_ELEMENT.value;
|
|
|
|
let metadata;
|
|
|
|
let key;
|
|
|
|
if (BUTTON_TOGGLE_ENCRYPTION_ELEMENT.classList.contains("active")) {
|
|
|
|
const encrypted = await Encryption.encrypt(await Encryption.generateEncryptionData(), value);
|
|
|
|
value = encrypted.result;
|
|
|
|
metadata = {
|
|
|
|
pf_encryption: {
|
|
|
|
alg: "AES-CBC",
|
|
|
|
iv: encrypted.iv
|
|
|
|
}
|
|
|
|
};
|
|
|
|
key = encrypted.key;
|
|
|
|
}
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
// Try to create the paste
|
2021-07-30 22:24:08 +03:00
|
|
|
const response = await API.createPaste(value, metadata);
|
2021-07-24 00:39:37 +03:00
|
|
|
if (!response.ok) {
|
|
|
|
Notifications.error("Error while creating paste: <b>" + await response.text() + "</b>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
// Display the modification token if provided
|
|
|
|
if (data.modificationToken) {
|
|
|
|
prompt("The modification token for your paste is:", data.modificationToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect the user to his newly created paste
|
2021-07-30 22:24:08 +03:00
|
|
|
location.replace(location.protocol + "//" + location.host + "/" + data.id + (key ? "#" + key : ""));
|
2021-07-24 00:39:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
BUTTON_EDIT_ELEMENT.addEventListener("click", toggleEditMode);
|
|
|
|
|
|
|
|
BUTTON_DELETE_ELEMENT.addEventListener("click", () => {
|
|
|
|
Spinner.surround(async () => {
|
|
|
|
// Ask for the modification token
|
|
|
|
const modificationToken = prompt("Modification token:");
|
|
|
|
if (!modificationToken) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to delete the paste
|
|
|
|
const response = await API.deletePaste(PASTE_ID, modificationToken);
|
|
|
|
if (!response.ok) {
|
|
|
|
Notifications.error("Error while deleting paste: <b>" + await response.text() + "</b>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redirect the user to the start page
|
|
|
|
location.replace(location.protocol + "//" + location.host);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
BUTTON_COPY_ELEMENT.addEventListener("click", async () => {
|
2022-01-29 01:40:45 +03:00
|
|
|
if (!navigator.clipboard) {
|
|
|
|
Notifications.error("Clipboard API not supported by your browser.");
|
2021-07-24 00:39:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await navigator.clipboard.writeText(CODE);
|
|
|
|
Notifications.success("Successfully copied the code.");
|
|
|
|
});
|
|
|
|
|
|
|
|
BUTTON_EDIT_CANCEL_ELEMENT.addEventListener("click", toggleEditMode);
|
|
|
|
|
|
|
|
BUTTON_EDIT_APPLY_ELEMENT.addEventListener("click", async () => {
|
|
|
|
// Only proceed if the input is not empty
|
|
|
|
if (!INPUT_ELEMENT.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask for the modification token
|
|
|
|
const modificationToken = prompt("Modification token:");
|
|
|
|
if (!modificationToken) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
// Re-encrypt the paste data if needed
|
|
|
|
let value = INPUT_ELEMENT.value;
|
|
|
|
if (ENCRYPTION_KEY && ENCRYPTION_IV) {
|
|
|
|
const encrypted = await Encryption.encrypt(await Encryption.encryptionDataFromHex(ENCRYPTION_KEY, ENCRYPTION_IV), value);
|
|
|
|
value = encrypted.result;
|
|
|
|
}
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
// Try to edit the paste
|
2021-07-30 22:24:08 +03:00
|
|
|
const response = await API.editPaste(PASTE_ID, modificationToken, value);
|
2021-07-24 00:39:37 +03:00
|
|
|
if (!response.ok) {
|
|
|
|
Notifications.error("Error while editing paste: <b>" + await response.text() + "</b>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the code and leave the edit mode
|
|
|
|
CODE = INPUT_ELEMENT.value;
|
|
|
|
updateCode();
|
|
|
|
toggleEditMode();
|
|
|
|
Notifications.success("Successfully edited paste.");
|
|
|
|
});
|
|
|
|
|
2021-07-30 22:24:08 +03:00
|
|
|
BUTTON_TOGGLE_ENCRYPTION_ELEMENT.addEventListener("click", () => {
|
|
|
|
const active = BUTTON_TOGGLE_ENCRYPTION_ELEMENT.classList.toggle("active");
|
|
|
|
localStorage.setItem("encryption", active);
|
2021-09-09 19:20:00 +03:00
|
|
|
Notifications.success((active ? "Enabled" : "Disabled") + " automatic paste encryption.");
|
2021-07-30 22:24:08 +03:00
|
|
|
});
|
|
|
|
|
2021-07-24 00:39:37 +03:00
|
|
|
BUTTON_REPORT_ELEMENT.addEventListener("click", async () => {
|
|
|
|
// Ask the user for a reason
|
|
|
|
const reason = prompt("Reason:");
|
|
|
|
if (!reason) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to report the paste
|
|
|
|
const response = await API.reportPaste(PASTE_ID, reason);
|
|
|
|
if (!response.ok) {
|
|
|
|
Notifications.error("Error while reporting paste: <b>" + await response.text() + "</b>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show the response message
|
|
|
|
const data = await response.json();
|
|
|
|
if (!data.success) {
|
|
|
|
Notifications.error("Error while reporting paste: <b>" + data.message + "</b>");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Notifications.success(data.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 1:1 skid from https://stackoverflow.com/questions/7404366/how-do-i-insert-some-text-where-the-cursor-is
|
|
|
|
function insertTextAtCursor(element, text) {
|
|
|
|
let value = element.value, endIndex, range, doc = element.ownerDocument;
|
|
|
|
if (typeof element.selectionStart == "number"
|
|
|
|
&& typeof element.selectionEnd == "number") {
|
|
|
|
endIndex = element.selectionEnd;
|
|
|
|
element.value = value.slice(0, endIndex) + text + value.slice(endIndex);
|
|
|
|
element.selectionStart = element.selectionEnd = endIndex + text.length;
|
|
|
|
} else if (doc.selection != "undefined" && doc.selection.createRange) {
|
|
|
|
element.focus();
|
|
|
|
range = doc.selection.createRange();
|
|
|
|
range.collapse(false);
|
|
|
|
range.text = text;
|
|
|
|
range.select();
|
|
|
|
}
|
|
|
|
}
|