Browse Source

Add "Paste" mode for code and mono posts

Users will see paste.as returned, instead of write.as.
tags/v2.0
Matt Baer 7 years ago
parent
commit
fd150bef65
3 changed files with 30 additions and 5 deletions
  1. +5
    -1
      context.js
  2. +8
    -1
      popup.html
  3. +17
    -3
      popup.js

+ 5
- 1
context.js View File

@@ -20,7 +20,11 @@ function publish(content, font) {
data = JSON.parse(http.responseText);
// Pull out data parts
id = data.data.id;
url = "https://write.as/"+id;
if (font == 'code' || font === 'mono') {
url = "https://paste.as/"+id;
} else {
url = "https://write.as/"+id;
}
editToken = data.data.token;
// Save the data


+ 8
- 1
popup.html View File

@@ -38,8 +38,15 @@
color: white;
text-align: right;
margin-left: 0.5em;
width: 7em;
text-align: center;
transition: all .2s ease-out;
border-radius: .25em;
}
input[type=submit].disabled {
input[type=submit]:hover {
background-color: #7d82c4;
}
input[type=submit].disabled, input[type=submit].disabled:hover {
background: #ddd;
color: #999;
border-color: #eee;


+ 17
- 3
popup.js View File

@@ -8,7 +8,7 @@ function publish(content, font) {
}
$publish.classList.add('disabled');
$publish.value = "Publishing...";
setPublishText(font, true);
$publish.disabled = true;
var post = H.getTitleStrict(content);
@@ -25,7 +25,7 @@ function publish(content, font) {
http.onreadystatechange = function() {
if (http.readyState == 4) {
$publish.classList.remove('disabled');
$publish.value = "Publish";
setPublishText(font, false);
$publish.disabled = false;
if (http.status == 201) {
@@ -34,7 +34,11 @@ function publish(content, font) {
data = JSON.parse(http.responseText);
// Pull out data parts
id = data.data.id;
url = "https://write.as/"+id;
if (font == 'code' || font === 'mono') {
url = "https://paste.as/"+id;
} else {
url = "https://write.as/"+id;
}
editToken = data.data.token;

document.getElementById("publish-holder").style.display = 'none';
@@ -57,6 +61,14 @@ function publish(content, font) {
http.send(params);
}

function setPublishText(font, isPublishing) {
if (font === 'code' || font === 'mono') {
$publish.value = isPublishing ? 'Pasting...' : 'Paste';
} else {
$publish.value = isPublishing ? 'Publishing...' : 'Publish';
}
}

document.addEventListener('DOMContentLoaded', function() {
$content = document.getElementById("content");
$publish = document.getElementById("publish");
@@ -123,10 +135,12 @@ document.addEventListener('DOMContentLoaded', function() {
// load font setting
H.load(fontRadios, 'font');
$content.className = fontRadios.value;
setPublishText(fontRadios.value, false);
// bind font changing action
for(var i = 0; i < fontRadios.length; i++) {
fontRadios[i].onclick = function() {
$content.className = this.value;
setPublishText(this.value, false);
H.save(fontRadios, 'font');
};
}


Loading…
Cancel
Save