From add1a3c51d901ca5e76c542df3af1535d05c3f3e Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 2 May 2015 09:56:35 -0400 Subject: [PATCH 01/15] Clean up non-working code and logs --- popup.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/popup.js b/popup.js index 45c919c..58e22f6 100644 --- a/popup.js +++ b/popup.js @@ -15,14 +15,8 @@ function publish(content, font) { var url = "https://write.as/api/"; var params = "w=" + encodeURIComponent(content) + "&font=" + font; http.open("POST", url, true); - - //Send the proper header information along with the request - http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - http.setRequestHeader("User-Agent", "Write.as Chrome Extension v1.0"); - http.setRequestHeader("Content-length", params.length); - http.setRequestHeader("Connection", "close"); - http.onreadystatechange = function() { //Call a function when the state changes. + http.onreadystatechange = function() { if (http.readyState == 4) { $publish.classList.remove('disabled'); $publish.value = "Publish"; @@ -44,8 +38,6 @@ function publish(content, font) { $url.value = url; var $urlLink = document.getElementById("url-link"); $urlLink.href = url; - - console.log("writeas add " + id + " " + editToken); } else { alert("Failed to post. Please try again."); } From 1b4138125acff55dc7f9cf65aba0d2d2016e58a0 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 7 Mar 2016 22:57:01 -0500 Subject: [PATCH 02/15] Send rtl=auto with posts Tells the API to automatically determine if RTL based on the lang parameter. T88 --- context.js | 2 +- popup.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/context.js b/context.js index 886c6d7..bf09137 100644 --- a/context.js +++ b/context.js @@ -3,7 +3,7 @@ function publish(content, font) { var url = "https://write.as/api/"; var lang = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage); lang = lang.substring(0, 2); - var params = "w=" + encodeURIComponent(content) + "&font=" + font + "&lang=" + lang; + var params = "w=" + encodeURIComponent(content) + "&font=" + font + "&lang=" + lang + "&rtl=auto"; http.open("POST", url, true); //Send the proper header information along with the request diff --git a/popup.js b/popup.js index 826bfce..b5e2703 100644 --- a/popup.js +++ b/popup.js @@ -15,7 +15,7 @@ function publish(content, font) { var url = "https://write.as/api/"; var lang = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage); lang = lang.substring(0, 2); - var params = "w=" + encodeURIComponent(content) + "&font=" + font + "&lang=" + lang; + var params = "w=" + encodeURIComponent(content) + "&font=" + font + "&lang=" + lang + "&rtl=auto"; http.open("POST", url, true); //Send the proper header information along with the request From a394539d9e4a45cea205ee610afc781f62385134 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 7 Mar 2016 23:28:48 -0500 Subject: [PATCH 03/15] Rename extension to Write.as for Chrome T133 --- README.md | 8 ++++---- manifest.json | 4 ++-- popup.html | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6798533..30b9a72 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -Paste Chrome extension -====================== +Write.as Chrome extension +========================= -Paste lets you instantly share text or code from your browser. +Write.as for Chrome lets you instantly share text from your browser. -![Selecting text in Paste](https://paste.as/images/pic01.jpg) +![Selecting text in Write.as](https://paste.as/images/pic01.jpg) # License diff --git a/manifest.json b/manifest.json index 5cad1b8..9c4c5b6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "manifest_version": 2, - "name": "Paste by Write.as", - "description": "Effortlessly share text online.", + "name": "Write.as for Chrome", + "description": "Effortlessly share text.", "version": "1.3", "icons": { diff --git a/popup.html b/popup.html index af1e62d..91cc716 100644 --- a/popup.html +++ b/popup.html @@ -1,7 +1,7 @@ - Paste by Write.as + Write.as @@ -100,6 +118,9 @@
+
+ Writing as write.as. Sync... +
diff --git a/popup.js b/popup.js index 3fb8ee7..e0cb3ca 100644 --- a/popup.js +++ b/popup.js @@ -41,6 +41,7 @@ function publish(content, font) { } editToken = data.data.token; + document.getElementById("account-tools").style.display = 'none'; document.getElementById("publish-holder").style.display = 'none'; document.getElementById("result-holder").style.display = 'inline'; @@ -49,10 +50,12 @@ function publish(content, font) { var $urlLink = document.getElementById("url-link"); $urlLink.href = url; - // Save the data - posts = JSON.parse(H.get('posts', '[]')); - posts.push(H.createPost(id, editToken, content)); - H.set('posts', JSON.stringify(posts)); + // Save the data if user wasn't logged in + if (typeof data.data.owner === 'undefined' || data.data.owner == "") { + posts = JSON.parse(H.get('posts', '[]')); + posts.push(H.createPost(id, editToken, post.content)); + H.set('posts', JSON.stringify(posts)); + } } else { alert("Failed to post. Please try again."); } @@ -112,6 +115,80 @@ document.addEventListener('DOMContentLoaded', function() { chrome.runtime.sendMessage({msg: $content.value}); }); }); + + document.getElementById('sync').addEventListener('click', function(e) { + e.preventDefault(); + var posts = JSON.parse(H.get('posts', '[]')); + + var p = "There "; + p += ((posts.length==1?'is ':'are ') + posts.length + " post" + (posts.length==1?'':'s')); + var thePosts = posts.length == 1 ? 'it' : 'them'; + p += " saved on this computer.\n\nSyncing "+thePosts+" to your account gives you access to "+thePosts+" from anywhere. Sync now?"; + if (!confirm(p)) { + return; + } + + var $sync = this; + $sync.innerText = "Syncing now..."; + $sync.className = 'disabled'; + + var http = new XMLHttpRequest(); + var params = []; + for (var i=0; i 0) { + if (res.data.length != posts.length) { + // TODO: handle this serious situation + console.error("Request and result array length didn't match!"); + return; + } + for (var i=0; i 0) { + document.getElementById('sync').style.display = 'inline'; + } else { + document.getElementById('sync').style.display = 'none'; + } + //document.getElementById("sync-count").innerText = posts.length + " post" + (posts.length==1?'':'s'); + document.getElementById("username").innerText = data.username; + } + } + } + http.send(); + } + handleRegUser(); if (H.get('updatedPostsMeta', '') == '') { // Add metadata used by Pad to all saved posts From 224c9f58d32d99a600a7bad0173abcfebc2247b1 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 6 Jul 2016 02:55:36 -0400 Subject: [PATCH 12/15] Add fallback sans fonts --- popup.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/popup.html b/popup.html index b297f21..563b832 100644 --- a/popup.html +++ b/popup.html @@ -6,8 +6,7 @@ body, input[type=submit], label[for=norm], textarea.norm { font-family: Lora, serif; } - #url, #result-holder, label[for=sans], textarea.sans { - font-family: 'Open Sans', sans-serif; + font-family: 'Open Sans', 'Segoe UI', Tahoma, Arial, sans-serif; } body { font-size: 100%; From bfdc0d081f319127d87420f47438c7bd0d6e06f1 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 6 Jul 2016 02:56:09 -0400 Subject: [PATCH 13/15] Support `wrap` posts Also: - Reflects the chosen font appearance's text wrapping properties in the window - Makes radio button labels smaller --- popup.html | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/popup.html b/popup.html index 563b832..67f47c7 100644 --- a/popup.html +++ b/popup.html @@ -60,10 +60,16 @@ width: 18em; margin-right: 0.5em; } - label[for=mono], label[for=code], textarea.mono, textarea.code { + label[for=mono], label[for=wrap], label[for=code], textarea.mono, textarea.wrap, textarea.code { font-family: monospace, monospace; font-size: 1em; } + textarea.mono, textarea.code { + white-space: pre; + } + label, label[for=mono], label[for=wrap], label[for=code] { + font-size: 0.86em; + } body.popout #publish-holder, body.popout #result-holder { position: fixed; bottom: 1em; @@ -129,6 +135,7 @@ + From a6ca80c664768c5132362fb0e3ed16cad4edd12e Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 6 Jul 2016 03:00:23 -0400 Subject: [PATCH 14/15] Revert "Add fallback sans fonts" This reverts commit 224c9f58d32d99a600a7bad0173abcfebc2247b1. --- popup.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/popup.html b/popup.html index 67f47c7..723ceb3 100644 --- a/popup.html +++ b/popup.html @@ -6,7 +6,8 @@ body, input[type=submit], label[for=norm], textarea.norm { font-family: Lora, serif; } - font-family: 'Open Sans', 'Segoe UI', Tahoma, Arial, sans-serif; + #url, #result-holder, label[for=sans], textarea.sans { + font-family: 'Open Sans', sans-serif; } body { font-size: 100%; From b5765349a8f8c38ddb9725c1845dd8e5d85ca936 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 6 Jul 2016 03:02:47 -0400 Subject: [PATCH 15/15] Bump version to 2.0 --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 1c5c041..07ca000 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "Write.as for Chrome", "short_name": "Write.as", "description": "Publish a thought in seconds.", - "version": "1.3", + "version": "2.0", "icons": { "16": "icon16.png",