Sha256: b4880e10d77bac5e799aa7c6d220a3bdf0a1bd5f0f670a17edac95eb43a6916e

Contents?: true

Size: 776 Bytes

Versions: 1

Compression:

Stored size: 776 Bytes

Contents

#!/usr/bin/env ruby

require 'open-uri'
require 'nokogiri'
require 'rbconfig'
require "scrapedown"

def interval
  sleep 1
  puts "\n"
end

unless RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
  puts "This command is unavailable in your OS."
  exit
end

charset = nil

loop{
  puts "enter URL or enter 'exit' to exit"

  url = gets.chomp
  exit if url == 'exit'
  next if url.empty?

  begin
    html = open(url) do |f|
      charset = f.charset
      f.read
    end
  rescue => e
    puts "Failed to open url!"
    interval
    next
  end
  doc = Nokogiri::HTML.parse(html, nil, charset)
  markdown_title = "[#{doc.title}](#{url})"

  # puts "charset: #{charset}"
  puts markdown_title
  system "echo '#{markdown_title}' | pbcopy"
  puts "copied to clipboard!"
  interval
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrapedown-0.1.0 exe/scrapedown