Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cmfcmf/7154536 to your computer and use it in GitHub Desktop.
Save cmfcmf/7154536 to your computer and use it in GitHub Desktop.
Creating and developing own tumblr themes has always been a pitty. However, this single line of javascript will help you A LOT. Follow the instuctions in the first comment below to get your own live version of your theme.
setInterval(function() {
jQuery.ajax('YOUR-URL-TO-THE-THEME-FILE', {cache: false}).success(function(html) {
var btn = jQuery("div[data-action='update_preview']").first();
if (html!=ace.edit('editor').getValue()) {
ace.edit('editor').setValue(html);
if (!btn.hasClass('disabled'))
btn.click()
}
});
},1000);
setInterval(function(){jQuery.ajax('YOUR-URL-TO-THE-THEME-FILE',{cache:false}).success(function(html){var btn=jQuery("div[data-action='update_preview']").first();if(html!=ace.edit('editor').getValue()){ace.edit('editor').setValue(html);if(!btn.hasClass('disabled'))btn.click()}});},1000);
@cmfcmf
Copy link
Author

cmfcmf commented Oct 25, 2013

Howto:

  • Use JetBrains PhpStorm to edit your html theme file ( It is possible to use other editors, the only important thing is that the file has to be hosted on a (local or public) server. )
  • Click Open in browser in PhpStorm while viewing the file.
  • Your browser should open with an url like this: http://localhost:63342/TumblrTheme/index.html.
  • Paste this URL in the snippet above.
  • Open http://www.tumblr.com/customize/YOUR-BLOG-NAME.
  • Click Edit html.
  • Open your browsers javascript console.
  • Paste in the snippet above (remember changing the path to your theme file).
  • The preview now is auto-updated every second if the source has changed.

License (MIT)

Copyright (c) 2013 Christian Flach
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@stefanoortisi
Copy link

I got some security problems using this snippet.
As the tumblr customize page is on https and my static files are served over http, when I run the script from the console i get this javascript error:

Mixed Content: The page at 'https://www.tumblr.com/customize/BLOG_NAME' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://MY_FILE_URL?_=1432649213872'. This request has been blocked; the content must be served over HTTPS.

Any idea how could I solve that?

@jorgeluislazo
Copy link

In chrome, you can allow mixed content by clicking on the shield in the right side of the address bar and selecting "allow insecure scripts to run"
Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment