diff --git a/H.js b/H.js index 911093c..6d0f65a 100644 --- a/H.js +++ b/H.js @@ -78,4 +78,22 @@ var H = { return post; }, + getTitleStrict: function(content) { + var eol = content.indexOf("\n"); + var title = ""; + var newContent = content; + if (content.indexOf("# ") === 0) { + // Title is in the format: + // # Some title + if (eol !== -1) { + // First line should start with # and end with \n + newContent = content.substring(eol).leftTrim(); + title = content.substring("# ".length, eol); + } + } + return { + title: title, + content: newContent + }; + }, }; 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/context.js b/context.js index 886c6d7..3510617 100644 --- a/context.js +++ b/context.js @@ -1,9 +1,14 @@ function publish(content, font) { + if (content.trim() == "") { + return; + } + + var post = H.getTitleStrict(content); var http = new XMLHttpRequest(); - var url = "https://write.as/api/"; + var url = "https://write.as/api/posts"; 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 = "body=" + encodeURIComponent(post.content) + "&title=" + encodeURIComponent(post.title) + "&font=" + font + "&lang=" + lang + "&rtl=auto"; http.open("POST", url, true); //Send the proper header information along with the request @@ -11,18 +16,24 @@ function publish(content, font) { http.onreadystatechange = function() { if (http.readyState == 4) { - if (http.status == 200) { - data = http.responseText.split("\n"); + if (http.status == 201) { + data = JSON.parse(http.responseText); // Pull out data parts - url = data[0]; - id = url.substr(url.lastIndexOf("/")+1); - editToken = data[1]; - - // Save the data - posts = JSON.parse(H.get('posts', '[]')); - posts.push(H.createPost(id, editToken, content)); - H.set('posts', JSON.stringify(posts)); - + id = data.data.id; + if (font == 'code' || font === 'mono') { + url = "https://paste.as/"+id; + } else { + url = "https://write.as/"+id; + } + editToken = data.data.token; + + // 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)); + } + // Launch post chrome.tabs.create({ url: url }); } else { diff --git a/fonts.css b/fonts.css new file mode 100644 index 0000000..f09061e --- /dev/null +++ b/fonts.css @@ -0,0 +1,18 @@ +@font-face { + font-family: 'Lora'; + font-style: normal; + font-weight: 400; + src: local('Lora'), local('Lora-Regular'), url('fonts/lora.woff2') format('woff2'); +} +@font-face { + font-family: 'Lora'; + font-style: normal; + font-weight: 700; + src: local('Lora Bold'), local('Lora-Bold'), url('fonts/lora-700.woff2') format('woff2'); +} +@font-face { + font-family: 'Open Sans'; + font-style: normal; + font-weight: 400; + src: local('Open Sans'), local('OpenSans'), url('fonts/open-sans.woff2') format('woff2'); +} diff --git a/fonts/lora-700.woff2 b/fonts/lora-700.woff2 new file mode 100644 index 0000000..2eacde2 Binary files /dev/null and b/fonts/lora-700.woff2 differ diff --git a/fonts/lora.woff2 b/fonts/lora.woff2 new file mode 100644 index 0000000..a3ef64d Binary files /dev/null and b/fonts/lora.woff2 differ diff --git a/fonts/open-sans.woff2 b/fonts/open-sans.woff2 new file mode 100644 index 0000000..5287058 Binary files /dev/null and b/fonts/open-sans.woff2 differ diff --git a/img/ic_launch.svg b/img/ic_launch.svg new file mode 100644 index 0000000..ca89ba8 --- /dev/null +++ b/img/ic_launch.svg @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/manifest.json b/manifest.json index 5cad1b8..07ca000 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,10 @@ { "manifest_version": 2, - "name": "Paste by Write.as", - "description": "Effortlessly share text online.", - "version": "1.3", + "name": "Write.as for Chrome", + "short_name": "Write.as", + "description": "Publish a thought in seconds.", + "version": "2.0", "icons": { "16": "icon16.png", @@ -28,8 +29,7 @@ "activeTab", "contextMenus", "webRequest", - "*://*.write.as/", - "https://fonts.googleapis.com/" + "*://*.write.as/" ], "externally_connectable": { "matches": ["*://*.write.as/*"] diff --git a/popup.html b/popup.html index af1e62d..723ceb3 100644 --- a/popup.html +++ b/popup.html @@ -1,7 +1,7 @@
-