├── CONTRIBUTING.md
├── LICENSE
├── README.md
└── fmark.user.js
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to FMark
2 |
3 | If you want to contribute to FMark, please make sure you use 2 spaces for indentation and make sure it works with _both_ Tampermonkey
4 | and Greasemonkey
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 TJ Horner
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software", "FMark"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software. This license is applicable to any
14 | versions of FMark, from version 0.1 and above.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FMark
2 |
3 | Enable Markdown on Facebook comments and posts.
4 |
5 | 
6 |
7 | ## How to install FMark
8 |
9 | With [Tampermonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en) or [Greasemonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) installed, click this attractive install button:
10 |
11 |
12 |
13 | It's that simple! If you install FMark, please give it a star (and tell your friends if you like it, too!) Thanks!
14 |
15 | If there are any bugs in the Markdown converter, and it hasn't been reported [here](https://github.com/tjhorner/FMark/issues), please create a new issue and provide a detailed description of the bug. If it seems to be related to the Markdown translator itself, please check the [Marked](https://github.com/chjj/marked) issues list first. If you have any questions, [contact me!](mailto:me@tjhorner.com)
16 |
17 | **NOTE:** Your Facebook ID will be sent to a server along with what version of the script you're using. This is used to let other users know that you use it so you can use Markdown in chat. It looks like this:
18 |
19 | 
20 |
--------------------------------------------------------------------------------
/fmark.user.js:
--------------------------------------------------------------------------------
1 | // ==UserScript==
2 | // @name FMark
3 | // @namespace https://horner.tj/
4 | // @version 0.4.2
5 | // @description Enables Markdown on Facebook
6 | // @author TJ Horner
7 | // @match https://www.facebook.com/*
8 | // @match https://facebook.com/*
9 | // @exclude https://*.facebook.com/ai.php
10 | // @require https://raw.githubusercontent.com/chjj/marked/master/lib/marked.js
11 | // @require https://code.jquery.com/jquery.js
12 | // @grant GM_xmlhttpRequest
13 | // ==/UserScript==
14 |
15 | if(typeof(facebook) !== "undefined"){
16 | FacebookMarkdown = (function(){
17 | var users = {};
18 |
19 | var identServer = "hydro-poutine-5010.herokuapp.com";
20 |
21 | var getUser = function(id, callback){
22 | if(!users[id.toString()]){
23 | GM_xmlhttpRequest({
24 | method: "GET",
25 | url: "http://" + identServer + "/user?id=" + encodeURIComponent(id),
26 | onload: function(res) {
27 | var user = JSON.parse(res.responseText);
28 | users[user.id.toString()] = user;
29 | callback(user);
30 | }
31 | });
32 | }else{
33 | return users[id.toString()];
34 | }
35 | };
36 |
37 | var extractIdFromUrl = function(url){
38 | var userId = url.substr(25);
39 |
40 | if(userId.indexOf("profile.php") !== -1){
41 | userId = userId.substr(15);
42 | }
43 |
44 | return userId;
45 | };
46 |
47 | var getUserContent = function(){
48 | return $(".userContent:not([fmark-replaced]) p, .UFICommentBody:not([fmark-replaced]) span, ._5yl5:not([fmark-replaced]) span");
49 | };
50 |
51 | var replaceUserContent = function(){
52 | var userContent = getUserContent();
53 | // console.log("userContent", userContent);
54 | $.each(userContent, function(i, e){
55 | var $e = $(e);
56 | var $replacement = $(marked($e.text().replace("<", "<").replace(">", ">")));
57 | $e.parent().attr("fmark-replaced", true);
58 | $e.html($replacement[0].innerHTML);
59 | });
60 |
61 | $.each($(".titlebarText"), function(i, e){
62 | var $e = $(e);
63 | if($e.attr("fmark-checked") !== "true"){
64 | var extUserId = extractIdFromUrl($e.attr("href"));
65 | getUser(extUserId, function(user){
66 | console.log(user);
67 | // bug
68 | $e.parent().find(".fmarker").remove();
69 | if(user.hasExtension){
70 | $e.parent().prepend("(+FM)" + (user.version !== GM_info.script.version ? " [v" + user.version + "]" : "") + " ");
71 | $e.attr("fmark-checked", true);
72 | }else{
73 | $e.parent().prepend("(-FM) ");
74 | $e.attr("fmark-checked", true);
75 | }
76 | });
77 | }
78 | });
79 | };
80 |
81 | $(document).ready(function(){
82 | // listen for DOM changes, then act on them
83 | var observer = new MutationObserver(replaceUserContent);
84 |
85 | observer.observe(document.body, {
86 | subtree: true,
87 | childList: true,
88 | attribute: true,
89 | });
90 |
91 | var userId = extractIdFromUrl($("._2dpe._1ayn").attr("href"));
92 |
93 | GM_xmlhttpRequest({
94 | method: "GET",
95 | url: "http://" + identServer + "/identify?id=" + encodeURIComponent(userId) + "&version=" + encodeURIComponent(GM_info.script.version),
96 | onload: function(res) {
97 | console.log("registered with server, verifying");
98 | getUser(userId, function(user){
99 | if(user.version === GM_info.script.version){
100 | console.log("server registration complete");
101 | }
102 | });
103 | }
104 | });
105 | });
106 |
107 | return "hi!";
108 | }());
109 | }
110 |
--------------------------------------------------------------------------------