Class: ICAPrb::Plugins::RemoveRetweetButton
- Inherits:
-
Object
- Object
- ICAPrb::Plugins::RemoveRetweetButton
- Defined in:
- lib/icaprb/filter/solution.rb
Overview
This class is used to delete common implementations of the Twitter-Share-Button
Constant Summary collapse
- PLUGIN_NAME =
class name
'remove_retweet_button'- MODES =
Available mod modes
[:response_mod]
Instance Method Summary collapse
-
#initialize(_, _) ⇒ RemoveRetweetButton
constructor
mode- resp or req mod
parameters -
All parameters given in the configuration file.
- resp or req mod
-
#plugin(data) ⇒ Object
- Execute plugin
data -
ICAP data.
- Execute plugin
Constructor Details
#initialize(_, _) ⇒ RemoveRetweetButton
mode-
resp or req mod
parameters-
All parameters given in the configuration file
367 368 |
# File 'lib/icaprb/filter/solution.rb', line 367 def initialize(_, _) end |
Instance Method Details
#plugin(data) ⇒ Object
Execute plugin
data-
ICAP data
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/icaprb/filter/solution.rb', line 377 def plugin(data) mod = false doc = Nokogiri::HTML(data[:http_response_body]) # removes twitter share button elements doc.search('a.twitter-share-button').each do |src| src.remove mod = true end # removes twitter timeline elements doc.search('a.twitter-timeline').each do |src| src.remove mod = true end # removes all matching links doc.search('a').each do |a| if a['href'].to_s.match(/twitter\.com\/share\?/i) a.remove mod = true end if a['href'].to_s.match(/twitter\.com\/intent\//i) a.remove mod = true end end # removes all scripts where the content matches doc.css('script').each do |script| if script.content.match(/\/\/platform\.twitter\.com\/widgets\.js/i) script.remove mod = true end end # removes all iframes where the source matches doc.search('iframe').each do |iframe| if iframe['src'].match(/platform\.twitter\.com\/widgets/i) iframe.remove mod = true end end data[:http_response_body] = doc.to_s if mod mod end |